﻿/*
*VMukti -- An open source video conferencing platform.
*
* Copyright (C) 2007 - 2008, VMukti Solutions Pvt. Ltd.
*
* Hardik Sanghvi <hardik@vmukti.com>
*
* See http://www.vmukti.com for more information about
* the VMukti project. Please do not directly contact
* any of the maintainers of this project for assistance;
* the project provides a web site, forums and mailing lists
* for your use.
*
* This program is free software, distributed under the terms of
* the GNU General Public License Version 2. See the LICENSE file
* at the top of the source tree.
*/
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlServerCe;
using System.IO;
using System.Net;
using System.Reflection;
using System.Windows;
using Microsoft.Synchronization.Data;
using Microsoft.Synchronization.Data.SqlServerCe;
using VMukti.Business;
using VMukti.Business.CommonDataContracts;
using VMukti.Business.WCFServices.BootStrapServices.BasicHttp;
using VMukti.Business.WCFServices.BootStrapServices.DataContracts;
using VMukti.Business.WCFServices.BootStrapServices.NetP2P;
using VMukti.Business.WCFServices.SuperNodeServices.BasicHttp;
using VMukti.Business.WCFServices.SuperNodeServices.NetP2P;
using VMukti.Presentation.Xml;
using VMuktiAPI;
using VMuktiService;
using System.Data.SqlClient;
using System.ServiceModel;

namespace VMukti.Presentation
{
	public class SuperNodeServiceDomain : IDisposable
	{
		object objHttpSuperNode = null;

        object objHttpDatabaseSuperNode = null;

		NetPeerServer npsSuperNodeServer = null;

		List<NetPeerServer> npsModules = new List<NetPeerServer>();
		public static List<clsNodeInfo> lstmyNodes = new List<clsNodeInfo>();

		FileStream objFileStream = null;
		string[] strBuddyName;

		int intModule = 1;

		//object objNetP2PBootStrapPredictive = null;
		//INetP2PBootStrapPreditiveService ClientNetP2PPredictiveChannel = null;

		object objNetP2PBootStrap = null;
		INetP2PBootStrapChannel clientNetP2pChannelBS = null;

		//object objNetP2PBootStrapPBX = null;
		//INetP2PBootStrapPBXServiceChannel ClientNetP2PPBXServerChannel = null;

		public static IHTTPBootStrapService clientHttpChannelBS = null;
		public static clsBootStrapInfo objSIPInformation;

		object objNetP2PSuperNode = null;
		public INetP2PSuperNodeChannel clientNetP2PChannelSN = null;

		string strMessageFor = string.Empty;
		//string strSchemaNumber = string.Empty;
		int intSchmaNumber = 0;
		List<string> lstSchmaInformation = new List<string>();

		bool blIsSNListPresent = false;
		public ArrayList al = new ArrayList();
		Assembly a;
		Assembly ass;
		Assembly assDownload;
		private List<clsRTCAuthClient> lstObjRTCAuthClient = new List<clsRTCAuthClient>();
		List<object> lstObjSuperNode = new List<object>();

        SqlCeConnection LocalSQLConn = null;
        string ClientConnectionString = @"Data Source=" + AppDomain.CurrentDomain.BaseDirectory + "SuperNodeBuddyInfo.sdf";
        string strLocalDBPath = AppDomain.CurrentDomain.BaseDirectory + "SuperNodeBuddyInfo.sdf";

		#region This Code has been added by Nisarg
		YatePBX.Presentation.YatePBX objPBX = new YatePBX.Presentation.YatePBX();
		#endregion

		public SuperNodeServiceDomain()
		{
			try
			{
				if (VMuktiInfo.CurrentPeer.CurrPeerType == PeerType.SuperNode || VMuktiInfo.CurrentPeer.CurrPeerType == PeerType.BootStrap)
				{
					if (!System.IO.File.Exists(AppDomain.CurrentDomain.BaseDirectory.ToString() + "sqlceme35.dll"))
					{
                        //new WebClient().DownloadFile("http://" + VMuktiAPI.VMuktiInfo.BootStrapIPs[0] + "/VMukti/sqlceme35.dll.zip", AppDomain.CurrentDomain.BaseDirectory.ToString() + "sqlceme35.dll");
                        //new WebClient().DownloadFile("http://" + VMuktiAPI.VMuktiInfo.BootStrapIPs[0] + "/VMukti/sqlceqp35.dll.zip", AppDomain.CurrentDomain.BaseDirectory.ToString() + "sqlceqp35.dll");
                        //new WebClient().DownloadFile("http://" + VMuktiAPI.VMuktiInfo.BootStrapIPs[0] + "/VMukti/sqlcese35.dll.zip", AppDomain.CurrentDomain.BaseDirectory.ToString() + "sqlcese35.dll");

                        new WebClient().DownloadFile(VMuktiAPI.VMuktiInfo.ZipFileDownloadLink + "sqlceme35.dll.zip", AppDomain.CurrentDomain.BaseDirectory.ToString() + "sqlceme35.dll");
                        new WebClient().DownloadFile(VMuktiAPI.VMuktiInfo.ZipFileDownloadLink + "sqlceqp35.dll.zip", AppDomain.CurrentDomain.BaseDirectory.ToString() + "sqlceqp35.dll");
                        new WebClient().DownloadFile(VMuktiAPI.VMuktiInfo.ZipFileDownloadLink + "sqlcese35.dll.zip", AppDomain.CurrentDomain.BaseDirectory.ToString() + "sqlcese35.dll");

					}

                    if (!System.IO.File.Exists(AppDomain.CurrentDomain.BaseDirectory.ToString() + "SuperNodeBuddyInfo.sdf"))
                    {
                        //new WebClient().DownloadFile("http://" + VMuktiAPI.VMuktiInfo.BootStrapIPs[0] + "/VMukti/AllocateConferenceNumber.sdf.zip", AppDomain.CurrentDomain.BaseDirectory.ToString() + "AllocateConferenceNumber.sdf");
                        //  new WebClient().DownloadFile(VMuktiAPI.VMuktiInfo.ZipFileDownloadLink + "AllocateConferenceNumber.sdf.zip", AppDomain.CurrentDomain.BaseDirectory.ToString() + "AllocateConferenceNumber.sdf");
                        
                        SqlCeEngine clientEngine = new SqlCeEngine(ClientConnectionString);
                        clientEngine.CreateDatabase();

                        LocalSQLConn = new SqlCeConnection();
                        LocalSQLConn.ConnectionString = ClientConnectionString;
                        LocalSQLConn.Open();


                        fncCreateBuddyStatusTable();
                        fncCreateSNNodeInfoTable();
                        fncCreateUserBuddyListTable();
                    }
                    else
                    {
                        LocalSQLConn = new SqlCeConnection();
                        LocalSQLConn.ConnectionString = ClientConnectionString;
                        LocalSQLConn.Open();
                    }

					#region Server
					#region HttpServerHoster

					objHttpSuperNode = new SuperNodeDelegates();
					((SuperNodeDelegates)objHttpSuperNode).EntHttpAddBuddies += new SuperNodeDelegates.DelHttpAddBuddies(SuperNodeServiceDomain_EntHttpAddBuddies);
					((SuperNodeDelegates)objHttpSuperNode).EntHttpRemoveBuddies += new SuperNodeDelegates.DelHttpRemoveBuddies(SuperNodeServiceDomain_EntHttpRemoveBuddies);
					
					((SuperNodeDelegates)objHttpSuperNode).EntHttpGetBuddies += new SuperNodeDelegates.DelHttpGetBuddies(SuperNodeServiceDomain_EntHttpGetBuddies);
					((SuperNodeDelegates)objHttpSuperNode).EntHttpsvcGetBuddyStatus += new SuperNodeDelegates.DelHttpsvcGetBuddyStatus(SuperNodeServiceDomain_EntHttpsvcGetBuddyStatus);
					((SuperNodeDelegates)objHttpSuperNode).EntHttpsvcjoin += new SuperNodeDelegates.DelHttpsvcJoin(SuperNodeServiceDomain_EntHttpsvcjoin);
					((SuperNodeDelegates)objHttpSuperNode).EntHttpsvcUnjoin += new SuperNodeDelegates.DelHttpsvcUnjoin(SuperNodeServiceDomain_EntHttpsvcUnjoin);
					((SuperNodeDelegates)objHttpSuperNode).EntIsSuperNodeAvailable += new SuperNodeDelegates.DelIsSuperNodeAvailable(SuperNodeServiceDomain_EntIsSuperNodeAvailable);
					((SuperNodeDelegates)objHttpSuperNode).EntsvcGetSpecialMsgs += new SuperNodeDelegates.DelsvcGetSpecialMsgs(SuperNodeServiceDomain_EntsvcGetSpecialMsgs);
					((SuperNodeDelegates)objHttpSuperNode).EntsvcSetSpecialMsg += new SuperNodeDelegates.DelsvcSetSpecialMsgs(SuperNodeServiceDomain_EntsvcSetSpecialMsg);
					((SuperNodeDelegates)objHttpSuperNode).EntsvcPageSetSpecialMsg += new SuperNodeDelegates.DelsvcPageSetSpecialMsgs(SuperNodeServiceDomain_EntsvcPageSetSpecialMsg);
					((SuperNodeDelegates)objHttpSuperNode).EntsvcAddDraggedBuddy += new SuperNodeDelegates.DelsvcAddDraggedBuddy(SuperNodeServiceDomain_EntsvcAddDraggedBuddy);
					((SuperNodeDelegates)objHttpSuperNode).EntsvcAddPageDraggedBuddy += new SuperNodeDelegates.DelsvcAddPageDraggedBuddy(SuperNodeServiceDomain_EntsvcAddPageDraggedBuddy);
					((SuperNodeDelegates)objHttpSuperNode).EntsvcSetRemoveDraggedBuddy += new SuperNodeDelegates.DelsvcSetRemoveDraggedBuddy(SuperNodeServiceDomain_EntsvcSetRemoveDraggedBuddy);
					((SuperNodeDelegates)objHttpSuperNode).EntsvcStartAService += new SuperNodeDelegates.DelsvcStartAService(SuperNodeServiceDomain_EntsvcStartAService);
					((SuperNodeDelegates)objHttpSuperNode).EntIsAutherizedUser += new SuperNodeDelegates.DelIsAutherizedUser(SuperNodeServiceDomain_EntIsAuthorizedUser);
					((SuperNodeDelegates)objHttpSuperNode).EntIsAutherized += new SuperNodeDelegates.DelIsAutherized(SuperNodeServiceDomain_EntIsAuthorized);
					((SuperNodeDelegates)objHttpSuperNode).EntsvcAddSIPUser += new SuperNodeDelegates.DelsvcAddSIPUser(SuperNodeServiceDomain_EntsvcAddSIPUser);
					((SuperNodeDelegates)objHttpSuperNode).EntsvcGetConferenceNumber += new SuperNodeDelegates.DelsvcGetConferenceNumber(SuperNodeServiceDomain_EntsvcGetConferenceNumber);
					((SuperNodeDelegates)objHttpSuperNode).EntsvcRemoveSIPUser += new SuperNodeDelegates.DelsvcRemoveSIPUser(SuperNodeServiceDomain_EntsvcRemoveSIPUser);

                    ((SuperNodeDelegates)objHttpSuperNode).EntsvcGetNodeNameByIP += new SuperNodeDelegates.DelsvcGetNodeNameByIP(SuperNodeServiceDomain_EntsvcGetNodeNameByIP);

					BasicHttpServer bhsHttpSuperNode = new BasicHttpServer(ref objHttpSuperNode, "http://" + VMuktiInfo.CurrentPeer.SuperNodeIP + ":80/HttpSuperNode");
					bhsHttpSuperNode.AddEndPoint<IHttpSuperNodeService>("http://" + VMuktiInfo.CurrentPeer.SuperNodeIP + ":80/HttpSuperNode");
					bhsHttpSuperNode.OpenServer();


                    #region HttpDataBase Server

                    objHttpDatabaseSuperNode = new DataBaseDelegates();
                    ((DataBaseDelegates)objHttpDatabaseSuperNode).EntHttpsvcjoin += new DataBaseDelegates.DelHttpsvcJoin(SuperNodeServiceDomain_EntHttpsvcjoin);
                    ((DataBaseDelegates)objHttpDatabaseSuperNode).EntHttpExecuteDataSet += new DataBaseDelegates.DelHttpExecuteDataSet(SuperNodeServiceDomain_EntHttpExecuteDataSet);
                    ((DataBaseDelegates)objHttpDatabaseSuperNode).EntHttpExecuteStoredProcedure += new DataBaseDelegates.DelHttpExecuteStoredProcedure(SuperNodeServiceDomain_EntHttpExecuteStoredProcedure);
                    ((DataBaseDelegates)objHttpDatabaseSuperNode).EntHttpExecuteNonQuery += new DataBaseDelegates.DelHttpExecuteNonQuery(SuperNodeServiceDomain_EntHttpExecuteNonQuery);
                    ((DataBaseDelegates)objHttpDatabaseSuperNode).EntHttpExecuteReturnNonQuery += new DataBaseDelegates.DelHttpExecuteReturnNonQuery(SuperNodeServiceDomain_EntHttpExecuteReturnNonQuery);
                    BasicHttpServer bhsHttpDataBase = new BasicHttpServer(ref objHttpDatabaseSuperNode, "http://" + VMuktiInfo.CurrentPeer.SuperNodeIP + ":80/HttpDataBase");
                    bhsHttpDataBase.AddEndPoint<IHttpDataBaseService>("http://" + VMuktiInfo.CurrentPeer.SuperNodeIP + ":80/HttpDataBase");
                    bhsHttpDataBase.OpenServer();

                    #endregion

                    #endregion

                    #region NetP2PServerHoster
                    try
					{
						npsSuperNodeServer = new NetPeerServer("net.tcp://" + VMuktiInfo.CurrentPeer.SuperNodeIP + ":5002/NetP2PSuperNode");
						npsSuperNodeServer.AddEndPoint("net.tcp://" + VMuktiInfo.CurrentPeer.SuperNodeIP + ":5002/NetP2PSuperNode");
						npsSuperNodeServer.OpenServer();
					}
					catch (Exception ex)
					{
						//MessageBox.Show(ex.Message);
						ex.Data.Add("My Key", "SuperNodeServiceDomain()--:--SuperNodeDomain.cs--:--" + ex.Message + " :--:--");
						ClsException.LogError(ex);
						ClsException.WriteToErrorLogFile(ex);
					}
					#endregion

					#endregion

					#region Client

					#region P2PBootStrap Client

					try
					{
						NetPeerClient npcBootStrapClient = new NetPeerClient();
						objNetP2PBootStrap = new NetP2PBootStrapDelegates();

						((NetP2PBootStrapDelegates)objNetP2PBootStrap).EntsvcNetP2PAddUser += new NetP2PBootStrapDelegates.DelsvcNetP2PAddUser(SuperNodeServiceDomain_EntsvcNetP2PAddUser);
						((NetP2PBootStrapDelegates)objNetP2PBootStrap).EntsvcNetP2PGetBuddyInfo += new NetP2PBootStrapDelegates.DelsvcNetP2PGetBuddyInfo(SuperNodeServiceDomain_EntsvcNetP2PGetBuddyInfo);
						((NetP2PBootStrapDelegates)objNetP2PBootStrap).EntsvcNetP2PGetSuperNodeBuddyStatus += new NetP2PBootStrapDelegates.DelsvcNetP2PGetSuperNodeBuddyStatus(SuperNodeServiceDomain_EntsvcNetP2PGetSuperNodeBuddyStatus);
						((NetP2PBootStrapDelegates)objNetP2PBootStrap).EntsvcNetP2PRemoveUser += new NetP2PBootStrapDelegates.DelsvcNetP2PRemoveUser(SuperNodeServiceDomain_EntsvcNetP2PRemoveUser);
						((NetP2PBootStrapDelegates)objNetP2PBootStrap).EntsvcNetP2PReturnBuddyInfo += new NetP2PBootStrapDelegates.DelsvcNetP2PReturnBuddyInfo(SuperNodeServiceDomain_EntsvcNetP2PReturnBuddyInfo);
						((NetP2PBootStrapDelegates)objNetP2PBootStrap).EntsvcNetP2PAddBuddies += new NetP2PBootStrapDelegates.DelsvcNetP2PAddBuddies(SuperNodeServiceDomain_EntsvcNetP2PAddBuddies);
						((NetP2PBootStrapDelegates)objNetP2PBootStrap).EntsvcNetP2PRemoveBuddies += new NetP2PBootStrapDelegates.DelsvcNetP2PRemoveBuddies(SuperNodeServiceDomain_EntsvcNetP2PRemoveBuddies);
						
						((NetP2PBootStrapDelegates)objNetP2PBootStrap).EntsvcNetP2PReturnSuperNodeBuddyStatus += new NetP2PBootStrapDelegates.DelsvcNetP2PReturnSuperNodeBuddyStatus(SuperNodeServiceDomain_EntsvcNetP2PReturnSuperNodeBuddyStatus);
						((NetP2PBootStrapDelegates)objNetP2PBootStrap).EntsvcNetP2PServiceJoin += new NetP2PBootStrapDelegates.DelsvcNetP2PServiceJoin(SuperNodeServiceDomain_EntsvcNetP2PServiceJoin);
						((NetP2PBootStrapDelegates)objNetP2PBootStrap).EntsvcNetP2PSetSpecialMsg += new NetP2PBootStrapDelegates.DelsvcNetP2PSetSpecialMsg(SuperNodeServiceDomain_EntsvcNetP2PSetSpecialMsg);
						((NetP2PBootStrapDelegates)objNetP2PBootStrap).EntsvcNetP2PPageSetSpecialMsg += new NetP2PBootStrapDelegates.DelsvcNetP2PPageSetSpecialMsg(SuperNodeServiceDomain_EntsvcNetP2PPageSetSpecialMsg);
						((NetP2PBootStrapDelegates)objNetP2PBootStrap).EntsvcAddDraggedBuddy += new NetP2PBootStrapDelegates.DelsvcAddDraggedBuddy(SuperNodeServiceDomain_EntsvcAddDraggedBuddy);
						((NetP2PBootStrapDelegates)objNetP2PBootStrap).EntsvcAddPageDraggedBuddy += new NetP2PBootStrapDelegates.DelsvcAddPageDraggedBuddy(SuperNodeServiceDomain_EntsvcAddPageDraggedBuddy);
						((NetP2PBootStrapDelegates)objNetP2PBootStrap).EntsvcSetRemoveDraggedBuddy += new NetP2PBootStrapDelegates.DelsvcSetRemoveDraggedBuddy(SuperNodeServiceDomain_EntsvcSetRemoveDraggedBuddy);
						((NetP2PBootStrapDelegates)objNetP2PBootStrap).EntsvcNetP2PUnJoin += new NetP2PBootStrapDelegates.DelsvcNetP2PUnJoin(SuperNodeServiceDomain_EntsvcNetP2PUnJoin);

						clientNetP2pChannelBS = (INetP2PBootStrapChannel)npcBootStrapClient.OpenClient<INetP2PBootStrapChannel>("net.tcp://" + VMuktiInfo.BootStrapIPs[0] + ":4000/NetP2PBootStrap", "P2PBootStrapMesh", ref objNetP2PBootStrap);
						clientNetP2pChannelBS.svcNetP2PServiceJoin(VMuktiInfo.CurrentPeer.SuperNodeIP);

                        IOnlineStatus ostat = clientNetP2pChannelBS.GetProperty<IOnlineStatus>();
                        ostat.Online += new EventHandler(ostat_Online);
                        ostat.Offline += new EventHandler(ostat_Offline);

					}
					catch (Exception ex)
					{
						ex.Data.Add("My Key", "SuperNodeServiceDomain()--:--SuperNodeDomain.cs--:--" + ex.Message + " :--:--");
						ClsException.LogError(ex);
						MessageBox.Show("Could not connect to Server please try after some time");
						Environment.Exit(0);
					}
					#endregion

					#region P2PSuperNode Client
					NetPeerClient npcSuperNode = new NetPeerClient();
					objNetP2PSuperNode = new NetP2PSuperNodeDelegates();

					((NetP2PSuperNodeDelegates)objNetP2PSuperNode).EntsvcJoin += new NetP2PSuperNodeDelegates.DelsvcJoin(NetP2PSNDomain_EntsvcJoin);
					((NetP2PSuperNodeDelegates)objNetP2PSuperNode).EntsvcSetSpecialMsg += new NetP2PSuperNodeDelegates.DelsvcSetSpecialMsg(NetP2PSNDomain_EntsvcSetSpecialMsg);
					((NetP2PSuperNodeDelegates)objNetP2PSuperNode).EntsvcPageSetSpecialMsg += new NetP2PSuperNodeDelegates.DelsvcPageSetSpecialMsg(NetP2PSNDomain_EntsvcPageSetSpecialMsg);
					((NetP2PSuperNodeDelegates)objNetP2PSuperNode).EntsvcAddDraggedBuddy += new NetP2PSuperNodeDelegates.DelsvcAddDraggedBuddy(NetP2PSNDomain_EntsvcAddDraggedBuddy);
					((NetP2PSuperNodeDelegates)objNetP2PSuperNode).EntsvcAddPageDraggedBuddy += new NetP2PSuperNodeDelegates.DelsvcAddPageDraggedBuddy(NetP2PSNDomain_EntsvcAddPageDraggedBuddy);
					((NetP2PSuperNodeDelegates)objNetP2PSuperNode).EntsvcSetRemoveDraggedBuddy += new NetP2PSuperNodeDelegates.DelsvcSetRemoveDraggedBuddy(NetP2PSNDomain_EntsvcSetRemoveDraggedBuddy);
					((NetP2PSuperNodeDelegates)objNetP2PSuperNode).EntsvcUnJoin += new NetP2PSuperNodeDelegates.DelsvcUnJoin(NetP2PSNDomain_EntsvcUnJoin);

					clientNetP2PChannelSN = (INetP2PSuperNodeChannel)npcSuperNode.OpenClient<INetP2PSuperNodeChannel>("net.tcp://" + VMuktiInfo.CurrentPeer.SuperNodeIP + ":5002/NetP2PSuperNode", "P2PSuperNodeMesh", ref objNetP2PSuperNode);
					clientNetP2PChannelSN.svcJoin("Server");
					#endregion

					#region HttpBootStrap Client

					BasicHttpClient bhcBootStrap = new BasicHttpClient();
					clientHttpChannelBS = (IHTTPBootStrapService)bhcBootStrap.OpenClient<IHTTPBootStrapService>("http://" + VMuktiInfo.BootStrapIPs[0] + ":80/HttpBootStrap");

					clsPeerInfo objPeerInfo = new clsPeerInfo();
					objPeerInfo.objPeerInforation = VMuktiInfo.CurrentPeer.GetPeerDataContract();
					try
					{
						objSIPInformation = clientHttpChannelBS.svcHttpBSJoin(VMuktiInfo.CurrentPeer.DisplayName, objPeerInfo);
					}
					catch (Exception ex)
					{
						ex.Data.Add("My Key", "SuperNodeServiceDomain()--:--SuperNodeDomain.cs--:--" + ex.Message + " :--:--");
						ClsException.LogError(ex);
						MessageBox.Show("Could not connect to Server please try after some time");
						Environment.Exit(0);
					}
					if (objSIPInformation != null)
					{
						if (objSIPInformation.ConnectionString != "")
						{
							VMuktiAPI.VMuktiInfo.MainConnectionString = objSIPInformation.ConnectionString;
						}
						if (objSIPInformation.AuthType == "NotDecided")
						{
							VMuktiAPI.VMuktiInfo.CurrentPeer.CurrAuthType = AuthType.NotDecided;
						}
						else if (objSIPInformation.AuthType == "SQLAuthentication")
						{
							VMuktiAPI.VMuktiInfo.CurrentPeer.CurrAuthType = AuthType.SQLAuthentication;
						}
						else if (objSIPInformation.AuthType == "SIPAuthentication")
						{
       
							VMuktiAPI.VMuktiInfo.CurrentPeer.CurrAuthType = AuthType.SIPAuthentication;
						}
					}
					System.Threading.Thread thstart = new System.Threading.Thread(new System.Threading.ThreadStart(DownloadZipFiles));
					thstart.Start();
					#endregion

					#region WCF Servers For Call Center
					//#region P2PBootStrapPredictive Client

					//NetPeerClient npcBootStrapPredictiveClient = new NetPeerClient();
					//objNetP2PBootStrapPredictive = new NetP2PBootStrapPredictiveDelegate();
					//((NetP2PBootStrapPredictiveDelegate)objNetP2PBootStrapPredictive).EntsvcJoin += new NetP2PBootStrapPredictiveDelegate.DelsvcJoin(SuperNodeServiceDomain_EntsvcJoin);
					//((NetP2PBootStrapPredictiveDelegate)objNetP2PBootStrapPredictive).EntAddExtraCall += new NetP2PBootStrapPredictiveDelegate.DelsvcAddExtraCall(SuperNodeServiceDomain_EntAddExtraCall);
					//((NetP2PBootStrapPredictiveDelegate)objNetP2PBootStrapPredictive).EntRequestExtraCall += new NetP2PBootStrapPredictiveDelegate.DelsvcRequestExtraCall(SuperNodeServiceDomain_EntRequestExtraCall);
					//((NetP2PBootStrapPredictiveDelegate)objNetP2PBootStrapPredictive).EntSendExtraCall += new NetP2PBootStrapPredictiveDelegate.DelsvcSendExtraCall(SuperNodeServiceDomain_EntSendExtraCall);
					//((NetP2PBootStrapPredictiveDelegate)objNetP2PBootStrapPredictive).EntRemoveExtraCall += new NetP2PBootStrapPredictiveDelegate.DelsvcRemoveExtraCall(SuperNodeServiceDomain_EntRemoveExtraCall);
					//((NetP2PBootStrapPredictiveDelegate)objNetP2PBootStrapPredictive).EntRequestFunctionToExecute += new NetP2PBootStrapPredictiveDelegate.DelsvcRequestFunctionToExecute(SuperNodeServiceDomain_EntRequestFunctionToExecute);
					//((NetP2PBootStrapPredictiveDelegate)objNetP2PBootStrapPredictive).EntReplyFunctionExecuted += new NetP2PBootStrapPredictiveDelegate.DelsvcReplyFunctionExecuted(SuperNodeServiceDomain_EntReplyFunctionExecuted);
					//((NetP2PBootStrapPredictiveDelegate)objNetP2PBootStrapPredictive).EntHangUpCall += new NetP2PBootStrapPredictiveDelegate.DelsvcHangUpCall(SuperNodeServiceDomain_EntHangUpCall);
					//((NetP2PBootStrapPredictiveDelegate)objNetP2PBootStrapPredictive).EntUnJoin += new NetP2PBootStrapPredictiveDelegate.DelsvcUnJoin(SuperNodeServiceDomain_EntUnJoin);
					//ClientNetP2PPredictiveChannel = (INetP2PBootStrapPreditiveService)npcBootStrapPredictiveClient.OpenClient<INetP2PBootStrapPreditiveService>("net.tcp://" + VMuktiInfo.BootStrapIPs[0] + ":6000/NetP2PBootStrapPredictive", "P2PBootStrapPredictiveMesh", ref objNetP2PBootStrapPredictive);
					//ClientNetP2PPredictiveChannel.svcJoin("", "");
					//#endregion

					//#region NetP2PPBXClientHoster
					////NetPeerClient npcBootStrapPBXClient = new NetPeerClient();
					////objNetP2PBootStrapPBX = new NetP2PBootStrapPBXDelegate();
					////((NetP2PBootStrapPBXDelegate)objNetP2PBootStrapPBX).EntNetP2PPBXsvcJoin += new NetP2PBootStrapPBXDelegate.DelNetP2PPBXsvcJoin(BootstrapServiceDomain_EntNetP2PPBXsvcJoin);
					////((NetP2PBootStrapPBXDelegate)objNetP2PBootStrapPBX).EntNetP2PPBXsvcGetPBXschema += new NetP2PBootStrapPBXDelegate.DelNetP2PPBXsvcGetPBXschema(BootstrapServiceDomain_EntNetP2PPBXsvcGetPBXschema);
					////((NetP2PBootStrapPBXDelegate)objNetP2PBootStrapPBX).EntNetP2PPBXsvcPutPBXSchema += new NetP2PBootStrapPBXDelegate.DelNetP2PPBXsvcPutPBXSchema(BootstrapServiceDomain_EntNetP2PPBXsvcPutPBXSchema);
					////((NetP2PBootStrapPBXDelegate)objNetP2PBootStrapPBX).EntNetP2PPBXsvcInformOther += new NetP2PBootStrapPBXDelegate.DelNetP2PPBXsvcInformOther(BootstrapServiceDomain_EntNetP2PPBXsvcInformOther);
					////((NetP2PBootStrapPBXDelegate)objNetP2PBootStrapPBX).EntNetP2PPBXsvcUnJoin += new NetP2PBootStrapPBXDelegate.DelNetP2PPBXsvcUnJoin(BootstrapServiceDomain_EntNetP2PPBXsvcUnJoin);
					////ClientNetP2PPBXServerChannel = (INetP2PBootStrapPBXServiceChannel)npcBootStrapPBXClient.OpenClient<INetP2PBootStrapPBXServiceChannel>("net.tcp://" + VMuktiInfo.BootStrapIPs[0] + ":6001/NetP2PBootStrapPBX", "P2PBootStrapPBXMesh", ref objNetP2PBootStrapPBX);
					////ClientNetP2PPBXServerChannel.svcJoin();
					////if (VMuktiInfo.CurrentPeer.CurrPeerType == PeerType.BootStrap)
					////{
					////    strMessageFor = "ToBootStrap";
					////    intSchmaNumber = 401;
					////    VMuktiAPI.VMuktiInfo.strSchemaNumber = "401";
					////    ClientNetP2PPBXServerChannel.svcGetPBXschema("ToBootStrap", VMuktiInfo.BootStrapIPs[0].ToString());
					////}
					////else
					////{
					////    strMessageFor = "NotFotBS";
					////    ClientNetP2PPBXServerChannel.svcGetPBXschema("ToBootStrap", VMuktiAPI.VMuktiInfo.CurrentPeer.SuperNodeIP);
					////}
					//#endregion
					#endregion

					#endregion
					

					#region Strating PBX Server (This code has been added by Nisarg)
					try
					{
						objPBX.FncStartPBX(VMuktiAPI.VMuktiInfo.CurrentPeer.SuperNodeIP);
					}
					catch (Exception ex)
					{
						MessageBox.Show("Yet Start" + ex.Message);
						ex.Data.Add("My Key", "VMukti--:--Domains--:--SuperNodeServiceDomain.cs--:--SuperNodeServiceDomain()--");
						ClsException.LogError(ex);
						ClsException.WriteToErrorLogFile(ex);
					}
					#endregion
				}
			}
			catch (Exception ex)
			{
				ex.Data.Add("My Key", "SuperNodeServiceDomain()--:--SuperNodeServiceDomain.cs--:--" + ex.Message + " :--:--");
				ClsException.LogError(ex);
				ClsException.WriteToErrorLogFile(ex);
				//return null;
			}
        }

        void ostat_Offline(object sender, EventArgs e)
        {
            try
            {

                string NodeName = clientHttpChannelBS.svcGetOfflineNodeName(VMuktiAPI.VMuktiInfo.CurrentPeer.DisplayName, VMuktiAPI.VMuktiInfo.CurrentPeer.SuperNodeIP);
                if (NodeName != VMuktiAPI.VMuktiInfo.CurrentPeer.DisplayName)
                {
                    clientNetP2pChannelBS.svcNetP2PRemoveUser(NodeName);
                }
            }
            catch (Exception ex)
            {
                ex.Data.Add("My Key", "ostat_Offline()--:--SuperNodeServiceDomain.cs--:--" + ex.Message + " :--:--");
                ClsException.LogError(ex);
                ClsException.WriteToErrorLogFile(ex);
                //return null;
            }

        }

        void ostat_Online(object sender, EventArgs e)
        {
            try
            {
            }
            catch (Exception ex)
            {
                ex.Data.Add("My Key", "ostat_Online()--:--SuperNodeServiceDomain.cs--:--" + ex.Message + " :--:--");
                ClsException.LogError(ex);
                ClsException.WriteToErrorLogFile(ex);
                //return null;
            }
        }

        void SuperNodeServiceDomain_EntsvcGetNodeNameByIP(string NodeName, string NodeIP)
        {
            try
            {
                //call data access function to get budy name
                /*SqlCeConnection conn = new SqlCeConnection(ClientConnectionString);
                conn.Open();
                string cmdString = "Select Node_Name from  SuperNode_Info where SuperNode_Id='" + NodeIp + "' ";
                SqlCeCommand NodeSel = new SqlCeCommand(cmdString, conn);
                //ExecuteScalar("Select Node_Name from  SuperNode_Node_Info where SuperNode_Id='" + PreSupIP + "' ;", CommandType.Text, null);*/
                //string NodeName = clientHttpChannelBS.GetBudyByIp(NodeIp);
                if (NodeName != null && NodeName != string.Empty)
                {
                    //fncSNDeleteBuddy(uName);
                    fncSNInsertBuddy(NodeName, "Offline");
                    fncSNDeleteNode(NodeName);
                    fncUpdateUserBuddyStatus(NodeName, "Offline");
                }//end if

                clientNetP2pChannelBS.svcNetP2PRemoveUser(NodeName);
                clientHttpChannelBS.svcHttpBSUnJoin(NodeName,NodeIP,true);
            }
            catch (Exception ex)
            {
                ex.Data.Add("My Key", "SuperNodeServiceDomain_EntsvcGetNodeNameByIP()--:--SuperNodeServiceDomain.cs--:--" + ex.Message + " :--:--");
                ClsException.LogError(ex);
                ClsException.WriteToErrorLogFile(ex);
            }
        }

        #region Http DataBase EventHandlers

        int SuperNodeServiceDomain_EntHttpExecuteReturnNonQuery(string spName, clsSqlParameterContract objSParam)
        {
            try
            {
                int Result = -1;
                SqlConnection conn = new SqlConnection(VMuktiInfo.MainConnectionString);
                conn.Open();
                SqlCommand cmd = new SqlCommand();
                cmd.CommandText = spName;
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Connection = conn;
                if (objSParam != null && objSParam.objParam != null)
                {
                    for (int paramCnt = 0; paramCnt < objSParam.objParam.Count; paramCnt++)
                    {
                        SqlParameter sp = new SqlParameter();
                        sp.ParameterName = (string)objSParam.objParam[paramCnt].PName;
                        if (sp.Size != -1)
                        {
                            sp.Size = (int)objSParam.objParam[paramCnt].PSize;
                        }
                        sp.Value = (object)objSParam.objParam[paramCnt].PValue;

                        string direction = (string)objSParam.objParam[paramCnt].Direction;
                        string dbType = (string)objSParam.objParam[paramCnt].PDBType;

                        //Enum.GetNames(typeof(SqlDbType))

                        switch (direction)
                        {
                            case "Input":
                                {
                                    sp.Direction = ParameterDirection.Input;
                                    break;
                                }
                            case "InputOutput":
                                {
                                    sp.Direction = ParameterDirection.InputOutput;
                                    break;
                                }
                            case "Output":
                                {
                                    sp.Direction = ParameterDirection.Output;
                                    break;
                                }
                            case "ReturnValue":
                                {
                                    sp.Direction = ParameterDirection.ReturnValue;
                                    break;
                                }
                            default:
                                {
                                    break;
                                }

                        }

                        switch (dbType)
                        {
                            case "VarChar":
                                {
                                    sp.SqlDbType = SqlDbType.VarChar;
                                    break;
                                }
                            case "NVarChar":
                                {
                                    sp.SqlDbType = SqlDbType.NVarChar;

                                    break;
                                }
                            case "Char":
                                {
                                    sp.SqlDbType = SqlDbType.Char;

                                    break;
                                }
                            case "NChar":
                                {
                                    sp.SqlDbType = SqlDbType.NChar;

                                    break;
                                }
                            case "Text":
                                {
                                    sp.SqlDbType = SqlDbType.Text;

                                    break;
                                }
                            case "DateTime":
                                {
                                    sp.SqlDbType = SqlDbType.DateTime;

                                    break;
                                }
                            case "Int":
                                {
                                    sp.SqlDbType = SqlDbType.Int;

                                    break;
                                }
                            case "UniqueIdentifier":
                                {
                                    sp.SqlDbType = SqlDbType.UniqueIdentifier;

                                    break;
                                }

                            case "Bit":
                                {
                                    sp.SqlDbType = SqlDbType.Bit;

                                    break;
                                }

                            case "Float":
                                {
                                    sp.SqlDbType = SqlDbType.Float;

                                    break;
                                }

                            case "Decimal":
                                {
                                    sp.SqlDbType = SqlDbType.Decimal;

                                    break;
                                }
                            case "BigInt":
                                {
                                    sp.SqlDbType = SqlDbType.BigInt;

                                    break;
                                }
                            default:
                                {
                                    break;
                                }

                        }
                        cmd.Parameters.Add(sp);
                    }

                }

                cmd.ExecuteNonQuery();
                for (int i = 0; i < cmd.Parameters.Count; i++)
                {
                    if (cmd.Parameters[i].Direction == ParameterDirection.InputOutput || cmd.Parameters[i].Direction == ParameterDirection.Output)
                    {
                        Result = int.Parse(cmd.Parameters[i].Value.ToString());
                    }
                }
                conn.Close();
                conn.Dispose();
                cmd.Dispose();
                return Result;

            }
            catch (Exception exp)
            {
                exp.Data.Add("My Key", "SuperNodeServiceDomain_EntHttpExecuteStoredProcedure()--:--SuperNodeDomain.cs--:--" + exp.Message + " :--:--");
                ClsException.LogError(exp);
                ClsException.WriteToErrorLogFile(exp);
                return -1;
            }           
        }

        void SuperNodeServiceDomain_EntHttpExecuteNonQuery(string spName, clsSqlParameterContract objSParam)
        {
            try
            {
                SqlConnection conn = new SqlConnection(VMuktiInfo.MainConnectionString);
                conn.Open();
                SqlCommand cmd = new SqlCommand();
                cmd.CommandText = spName;
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Connection = conn;
                if (objSParam != null && objSParam.objParam != null)
                {
                    for (int paramCnt = 0; paramCnt < objSParam.objParam.Count; paramCnt++)
                    {
                        SqlParameter sp = new SqlParameter();
                        sp.ParameterName = (string)objSParam.objParam[paramCnt].PName;
                        if (sp.Size != -1)
                        {
                            sp.Size = (int)objSParam.objParam[paramCnt].PSize;
                        }
                        sp.Value = (object)objSParam.objParam[paramCnt].PValue;

                        string direction = (string)objSParam.objParam[paramCnt].Direction;
                        string dbType = (string)objSParam.objParam[paramCnt].PDBType;

                        //Enum.GetNames(typeof(SqlDbType))

                        switch (direction)
                        {
                            case "Input":
                                {
                                    sp.Direction = ParameterDirection.Input;
                                    break;
                                }
                            case "InputOutput":
                                {
                                    sp.Direction = ParameterDirection.InputOutput;
                                    break;
                                }
                            case "Output":
                                {
                                    sp.Direction = ParameterDirection.Output;
                                    break;
                                }
                            case "ReturnValue":
                                {
                                    sp.Direction = ParameterDirection.ReturnValue;
                                    break;
                                }
                            default:
                                {
                                    break;
                                }

                        }

                        switch (dbType)
                        {
                            case "VarChar":
                                {
                                    sp.SqlDbType = SqlDbType.VarChar;
                                    break;
                                }
                            case "NVarChar":
                                {
                                    sp.SqlDbType = SqlDbType.NVarChar;

                                    break;
                                }
                            case "Char":
                                {
                                    sp.SqlDbType = SqlDbType.Char;

                                    break;
                                }
                            case "NChar":
                                {
                                    sp.SqlDbType = SqlDbType.NChar;

                                    break;
                                }
                            case "Text":
                                {
                                    sp.SqlDbType = SqlDbType.Text;

                                    break;
                                }
                            case "DateTime":
                                {
                                    sp.SqlDbType = SqlDbType.DateTime;

                                    break;
                                }
                            case "Int":
                                {
                                    sp.SqlDbType = SqlDbType.Int;

                                    break;
                                }
                            case "UniqueIdentifier":
                                {
                                    sp.SqlDbType = SqlDbType.UniqueIdentifier;

                                    break;
                                }

                            case "Bit":
                                {
                                    sp.SqlDbType = SqlDbType.Bit;

                                    break;
                                }

                            case "Float":
                                {
                                    sp.SqlDbType = SqlDbType.Float;

                                    break;
                                }

                            case "Decimal":
                                {
                                    sp.SqlDbType = SqlDbType.Decimal;

                                    break;
                                }
                            case "BigInt":
                                {
                                    sp.SqlDbType = SqlDbType.BigInt;

                                    break;
                                }
                            default:
                                {
                                    break;
                                }

                        }
                        cmd.Parameters.Add(sp);


                    }

                }


                cmd.ExecuteNonQuery();
                conn.Close();
                conn.Dispose();
                cmd.Dispose();
            }
            catch (Exception exp)
            {
                exp.Data.Add("My Key", "SuperNodeServiceDomain_EntHttpExecuteStoredProcedure()--:--SuperNodeDomain.cs--:--" + exp.Message + " :--:--");
                ClsException.LogError(exp);
                ClsException.WriteToErrorLogFile(exp);
                
            }
        }

        clsDataBaseInfo SuperNodeServiceDomain_EntHttpExecuteStoredProcedure(string spName, clsSqlParameterContract objSParam)
        {
            try
            {
                SqlConnection conn = new SqlConnection(VMuktiInfo.MainConnectionString);
                conn.Open();
                SqlCommand cmd = new SqlCommand();
                cmd.CommandText = spName;
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Connection = conn;
                if (objSParam != null && objSParam.objParam != null)
                {
                    for (int paramCnt = 0; paramCnt < objSParam.objParam.Count; paramCnt++)
                    {
                        SqlParameter sp = new SqlParameter();
                        sp.ParameterName = (string)objSParam.objParam[paramCnt].PName;
                        if (sp.Size != -1)
                        {
                            sp.Size = (int)objSParam.objParam[paramCnt].PSize;
                        }
                        sp.Value = (object)objSParam.objParam[paramCnt].PValue;

                        string direction = (string)objSParam.objParam[paramCnt].Direction;
                        string dbType = (string)objSParam.objParam[paramCnt].PDBType;

                        //Enum.GetNames(typeof(SqlDbType))

                        switch (direction)
                        {
                            case "Input":
                                {
                                    sp.Direction = ParameterDirection.Input;
                                    break;
                                }
                            case "InputOutput":
                                {
                                    sp.Direction = ParameterDirection.InputOutput;
                                    break;
                                }
                            case "Output":
                                {
                                    sp.Direction = ParameterDirection.Output;
                                    break;
                                }
                            case "ReturnValue":
                                {
                                    sp.Direction = ParameterDirection.ReturnValue;
                                    break;
                                }
                            default:
                                {
                                    break;
                                }

                        }

                        switch (dbType)
                        {
                            case "VarChar":
                                {
                                    sp.SqlDbType = SqlDbType.VarChar;
                                    break;
                                }
                            case "NVarChar":
                                {
                                    sp.SqlDbType = SqlDbType.NVarChar;

                                    break;
                                }
                            case "Char":
                                {
                                    sp.SqlDbType = SqlDbType.Char;

                                    break;
                                }
                            case "NChar":
                                {
                                    sp.SqlDbType = SqlDbType.NChar;

                                    break;
                                }
                            case "Text":
                                {
                                    sp.SqlDbType = SqlDbType.Text;

                                    break;
                                }
                            case "DateTime":
                                {
                                    sp.SqlDbType = SqlDbType.DateTime;

                                    break;
                                }
                            case "Int":
                                {
                                    sp.SqlDbType = SqlDbType.Int;

                                    break;
                                }
                            case "UniqueIdentifier":
                                {
                                    sp.SqlDbType = SqlDbType.UniqueIdentifier;

                                    break;
                                }

                            case "Bit":
                                {
                                    sp.SqlDbType = SqlDbType.Bit;

                                    break;
                                }

                            case "Float":
                                {
                                    sp.SqlDbType = SqlDbType.Float;

                                    break;
                                }

                            case "Decimal":
                                {
                                    sp.SqlDbType = SqlDbType.Decimal;

                                    break;
                                }
                            case "BigInt":
                                {
                                    sp.SqlDbType = SqlDbType.BigInt;

                                    break;
                                }
                            default:
                                {
                                    break;
                                }

                        }
                        cmd.Parameters.Add(sp);


                    }

                }


                SqlDataAdapter sda = new SqlDataAdapter(cmd);
                clsDataBaseInfo dbContract = new clsDataBaseInfo();
                dbContract.dsInfo = new DataSet();
                sda.Fill(dbContract.dsInfo);
                sda.Dispose();
                conn.Close();
                conn.Dispose();
                cmd.Dispose();
                return dbContract;

            }
            catch (Exception exp)
            {
                exp.Data.Add("My Key", "SuperNodeServiceDomain_EntHttpExecuteStoredProcedure()--:--SuperNodeDomain.cs--:--" + exp.Message + " :--:--");
                ClsException.LogError(exp);
                ClsException.WriteToErrorLogFile(exp);
                return null;
            }

        }

        clsDataBaseInfo SuperNodeServiceDomain_EntHttpExecuteDataSet(string querystring)
        {
            try
            {
                SqlConnection conn = new SqlConnection(VMuktiInfo.MainConnectionString);
                SqlCommand cmd = new SqlCommand(querystring, conn);

                SqlDataAdapter sda = new SqlDataAdapter(cmd);
                clsDataBaseInfo dbContract = new clsDataBaseInfo();
                dbContract.dsInfo = new DataSet();
                sda.Fill(dbContract.dsInfo);
                sda.Dispose();
                conn.Close();
                conn.Dispose();
                cmd.Dispose();
                return dbContract;
            }
            catch (Exception exp)
            {
                exp.Data.Add("My Key", "SuperNodeServiceDomain_EntHttpExecuteDataSet()--:--SuperNodeDomain.cs--:--" + exp.Message + " :--:--");
                ClsException.LogError(exp);
                ClsException.WriteToErrorLogFile(exp);
                return null;
            }
        }

        void SuperNodeServiceDomain_EntHttpsvcjoin()
        {

        }

        #endregion

        #region WCF Functions for Call Center
        //#region WCF Functions of PBX Server
		//void BootstrapServiceDomain_EntNetP2PPBXsvcJoin()
		//{
		//}

		//void BootstrapServiceDomain_EntNetP2PPBXsvcGetPBXschema(string SchemaName, string IPAddress)
		//{
		//    if (strMessageFor == SchemaName)
		//    {
		//        lstSchmaInformation.Add(intSchmaNumber.ToString() + ":" + IPAddress);
		//        ClientNetP2PPBXServerChannel.svcPutPBXSchema(intSchmaNumber.ToString(), lstSchmaInformation);
		//        intSchmaNumber = intSchmaNumber + 1;
		//    }
		//}

		//void BootstrapServiceDomain_EntNetP2PPBXsvcPutPBXSchema(string SchemaName, List<string> PBXInfo)
		//{
		//    if (VMuktiAPI.VMuktiInfo.strSchemaNumber == string.Empty)
		//    {
		//        VMuktiAPI.VMuktiInfo.strSchemaNumber = SchemaName;
		//        //Call Function To Add IP Address in Yate File from List
		//        for (int i = 0; i < PBXInfo.Count; i++)
		//        {
		//            string[] strTemp = PBXInfo[i].Split(':');
		//            //objPBX.FncUpdateYATEFile(strTemp[0], strTemp[1]);
		//        }
		//        ClientNetP2PPBXServerChannel.svcInformOther(VMuktiAPI.VMuktiInfo.strSchemaNumber, VMuktiAPI.VMuktiInfo.CurrentPeer.SuperNodeIP);
		//    }
		//}

		//void BootstrapServiceDomain_EntNetP2PPBXsvcInformOther(string SchemaName, string IPAddress)
		//{
		//    //objPBX.FncUpdateYATEFile(SchemaName, IPAddress);
		//    //Call Function To Add IP address in Yate 
		//}

		//void BootstrapServiceDomain_EntNetP2PPBXsvcUnJoin(string schemaName)
		//{ }
		//#endregion

		//#region NetP2PBootStrapPredictive Event

		//void SuperNodeServiceDomain_EntsvcJoin(string UserNumber, string CampaignID)
		//{
		//}

		//void SuperNodeServiceDomain_EntAddExtraCall(string SenderUserNumber, string CampaignID, string PhoneNumber)
		//{
		//}

		//void SuperNodeServiceDomain_EntRequestExtraCall(string SenderUserNumber, string CampaignID, string CallRequestedUserNumber)
		//{
		//}

		//void SuperNodeServiceDomain_EntSendExtraCall(string SenderUserNumber, string CampaignID, string PhoneNumber, string CallRequesedUserNumber, string LeadID, string ConfNumber)
		//{
		//}

		//void SuperNodeServiceDomain_EntRemoveExtraCall(string SenderUserNumber, string CampaignID, string PhoneNumber)
		//{
		//}

		//void SuperNodeServiceDomain_EntRequestFunctionToExecute(string FunctionType, string To, string From)
		//{
		//}

		//void SuperNodeServiceDomain_EntReplyFunctionExecuted(string FunctionType, string To, string From, string ConfNumber)
		//{
		//}

		//void SuperNodeServiceDomain_EntHangUpCall(string AgentNumber)
		//{
		//}

		//void SuperNodeServiceDomain_EntUnJoin()
		//{
		//}

		//#endregion
		#endregion

		#region NetP2P BootStrap Event Handlers

		void SuperNodeServiceDomain_EntsvcNetP2PUnJoin(string uName)
		{

		}

		void SuperNodeServiceDomain_EntsvcNetP2PSetSpecialMsg(string from, string to, string msg, clsModuleInfo objModInfo, string IPAddress)
		{
            try
            {
                if (IPAddress != VMuktiInfo.CurrentPeer.SuperNodeIP)
                {
                    //clientNetP2PChannelSN.svcSetSpecialMsg(from, to, msg, objModInfo, IPAddress);
                    clientNetP2PChannelSN.svcSetSpecialMsg(from, to, msg, objModInfo, "~" + IPAddress);
                }
            }
            catch (Exception exp)
            {
                exp.Data.Add("My Key", "SuperNodeServiceDomain_EntsvcNetP2PSetSpecialMsg()--:--SuperNodeServiceDomain.cs--:--" + exp.Message + " :--:--");
                ClsException.LogError(exp);
                ClsException.WriteToErrorLogFile(exp);
            }
		}

        void SuperNodeServiceDomain_EntsvcNetP2PPageSetSpecialMsg(string from, string to, string msg, clsPageInfo objPageInfo, string IPAddress)
        {
            try
            {
                if (IPAddress != VMuktiInfo.CurrentPeer.SuperNodeIP)
                {
                    //clientNetP2PChannelSN.svcSetSpecialMsg(from, to, msg, objModInfo, IPAddress);
                    clientNetP2PChannelSN.svcSetSpecialMsg(from, to, msg, objPageInfo, "~" + IPAddress);
                }

            }
            catch (Exception exp)
            {
                exp.Data.Add("My Key", "SuperNodeServiceDomain_EntsvcNetP2PPageSetSpecialMsg()--:--SuperNodeServiceDomain.cs--:--" + exp.Message + " :--:--");
                ClsException.LogError(exp);
                ClsException.WriteToErrorLogFile(exp);
            }
        }

		void SuperNodeServiceDomain_EntsvcAddDraggedBuddy(string from, string to, string msg, clsModuleInfo objModInfo, string IPAddress)
        {
            try
            {
			if (IPAddress != VMuktiInfo.CurrentPeer.SuperNodeIP)
			{
				clientNetP2PChannelSN.svcAddDraggedBuddy(from, to, msg, objModInfo, "~" + IPAddress);
			}
            }
            catch (Exception exp)
            {
                exp.Data.Add("My Key", "SuperNodeServiceDomain_EntsvcAddDraggedBuddy()--:--SuperNodeServiceDomain.cs--:--" + exp.Message + " :--:--");
                ClsException.LogError(exp);
                ClsException.WriteToErrorLogFile(exp);
            }
		}

        void SuperNodeServiceDomain_EntsvcAddPageDraggedBuddy(string from, string to, string msg, List<clsModuleInfo> lstModuleInfo, string IPAddress)
        {
            try
            {
                if (IPAddress != VMuktiInfo.CurrentPeer.SuperNodeIP)
                {
                    clientNetP2PChannelSN.svcAddDraggedBuddy(from, to, msg, lstModuleInfo, "~" + IPAddress);
                }
            }
            catch (Exception exp)
            {
                exp.Data.Add("My Key", "SuperNodeServiceDomain_EntsvcAddDraggedBuddy()--List--:--SuperNodeServiceDomain.cs--:--" + exp.Message + " :--:--");
                ClsException.LogError(exp);
                ClsException.WriteToErrorLogFile(exp);
            }
        }

        void SuperNodeServiceDomain_EntsvcSetRemoveDraggedBuddy(string from, List<string> to, string msg, clsModuleInfo objModInfo, string IPAddress)
        {
            try
            {
                if (IPAddress != VMuktiInfo.CurrentPeer.SuperNodeIP)
                {
                    //clientNetP2PChannelSN.svcSetSpecialMsg(from, to, msg, objModInfo, IPAddress);
                    clientNetP2PChannelSN.svcSetRemoveDraggedBuddy(from, to, msg, objModInfo, "~" + IPAddress);
                }
            }
            catch (Exception exp)
            {
                exp.Data.Add("My Key", "SuperNodeServiceDomain_EntsvcSetRemoveDraggedBuddy()--:--SuperNodeServiceDomain.cs--:--" + exp.Message + " :--:--");
                ClsException.LogError(exp);
                ClsException.WriteToErrorLogFile(exp);
            }
        }

		void SuperNodeServiceDomain_EntsvcNetP2PServiceJoin(string sSuperNodeIP)
		{

		}

		//Code Added by Nisarg For Predictive Dialer Start
		void SuperNodeServiceDomain_EntsvcNetP2PAddExtraCall(string SenderUserNumber, string CampaignID, string PhoneNumber)
		{
		}

		void SuperNodeServiceDomain_EntsvcNetP2PRequestExtraCall(string SenderUserNumber, string CampaignID, string CallRequestedUserNumber)
		{ }

		void SuperNodeServiceDomain_EntsvcNetP2PSendExtraCall(string SenderUserNumber, string CampaignID, string PhoneNumber, string CallRequesedUserNumber, string LeadID)
		{ }

		void SuperNodeServiceDomain_EntsvcNetP2PRemoveExtraCall(string SenderUserNumber, string CampaignID, string PhoneNumber)
		{ }
		//code Added By Nisarg For Predictive Dialer Stop
		#endregion

		#region NetP2P SuperNode Event Handlers

		void NetP2PSNDomain_EntsvcUnJoin(string uname)
		{

		}

		void NetP2PSNDomain_EntsvcJoin(string uname)
		{

		}

		void NetP2PSNDomain_EntsvcSetSpecialMsg(string from, string to, string msg, clsModuleInfo objModInfo, string IPAddress)
		{

			#region OPEN MODULE
			try
			{

				bool blnNodePresent = false;

				for (int i = 0; i < lstmyNodes.Count; i++)
				{
					if (lstmyNodes[i].uname == to)
					{
						if (lstmyNodes[i].nodeBType == PeerType.NodeWithHttp)
						{
							clsMessage objmsg = new clsMessage();
							objmsg.strFrom = from;
							objmsg.strTo = new string[] { to };
							objmsg.strMessage = msg;
							string p2puri = objModInfo.strUri[0];
							string httpuri = "";

							System.Reflection.Assembly ass = System.Reflection.Assembly.GetAssembly(typeof(SuperNodeServiceDomain));

							ClsPod podObj = new ClsPod();
							podObj = ClsPod.GetModInfo(objModInfo.intModuleId);

							string modulename = podObj.ZipFile.Replace(".zip", "");

							string strModPath = ass.Location.Replace("VMukti.Presentation.exe", @"Modules");

							string strXmlPath = strModPath + "\\" + modulename + "\\Control\\configuration.xml";

							//string[] str = Directory.GetFiles(strXmlPath, ".xml");                    
							XmlParser xp = new XmlParser();
							xp.Parse(strXmlPath);

							#region Loading ReferencedAssemblies

							al.Clear();

							DirectoryInfo dirinfomodule = new DirectoryInfo(strModPath + "\\" + modulename);
							ShowDirectory(dirinfomodule);

							for (int j = 0; j < al.Count; j++)
							{
								string[] arraysplit = al[j].ToString().Split('\\');
								if (arraysplit[arraysplit.Length - 1].ToString() == podObj.AssemblyFile)
								{
									a = Assembly.LoadFrom(al[j].ToString());
									AssemblyName[] an = a.GetReferencedAssemblies();

									for (int alcount = 0; alcount < al.Count; alcount++)
									{
										string strsplit = al[alcount].ToString();
										string[] strold = strsplit.Split('\\');
										string strnew = strold[strold.Length - 1].Substring(0, strold[strold.Length - 1].Length - 4);

										for (int asscount = 0; asscount < an.Length; asscount++)
										{
											if (an[asscount].Name == strnew)
											{
												Assembly assbal = System.AppDomain.CurrentDomain.Load(System.Reflection.Assembly.LoadFrom(al[alcount].ToString()).GetName());
												AssemblyName[] anbal = assbal.GetReferencedAssemblies();
												for (int andal = 0; andal < al.Count; andal++)
												{
													string strsplitdal = al[andal].ToString();
													string[] strolddal = strsplitdal.Split('\\');
													string strnewdal = strolddal[strolddal.Length - 1].Substring(0, strolddal[strolddal.Length - 1].Length - 4);

													for (int asscountdal = 0; asscountdal < anbal.Length; asscountdal++)
													{
														if (anbal[asscountdal].Name == strnewdal)
														{
															Assembly assdal = System.AppDomain.CurrentDomain.Load(System.Reflection.Assembly.LoadFrom(al[andal].ToString()).GetName());
														}
													}
												}
											}
										}
									}
									Type[] t1 = a.GetTypes();

									CopyToBase(modulename, podObj.AssemblyFile);

									#region CreatingObject

									for (int k = 0; k < t1.Length; k++)
									{
										if (t1[k].Name == xp.xMain.DummyClassName)
										{
											try
											{

												object obj1 = Activator.CreateInstance(t1[k], VMuktiInfo.CurrentPeer.DisplayName);
												MethodInfo mi = t1[k].GetMethod(xp.xMain.DummyMethodName);

												object[] objparams = new object[3];
												objparams[0] = intModule;
												objparams[1] = p2puri;
												objparams[2] = VMuktiInfo.CurrentPeer.SuperNodeIP;
												httpuri = (mi.Invoke(obj1, objparams)).ToString();

											}

											catch (Exception exp)
											{
												MessageBox.Show("CreatingObject " + exp.Message);
											}
										}
									}
									#endregion
								}
							}
							#endregion
							objModInfo.strUri[1] = httpuri;
							objmsg.objClsModuleInfo = objModInfo;
							//string uri = objModInfo.strUri;
							lstmyNodes[i].lstMyMsgs.Add(objmsg);
							blnNodePresent = true;
							break;
						}
						else
						{
							blnNodePresent = true;
							break;
						}
					}
				}
				if (!blnNodePresent && IPAddress.Substring(0, 1) != "~")
				{
					clientNetP2pChannelBS.svcSetSpecialMsg(from, to, msg, objModInfo, VMuktiInfo.CurrentPeer.SuperNodeIP);
				}

			}
			catch (Exception exp)
			{
				exp.Data.Add("My Key", "NetP2PSNDomain_EntsvcSetSpecialMsg()--:--SuperNodeServiceDomain.cs--:--" + exp.Message + " :--:--");
				ClsException.LogError(exp);
				ClsException.WriteToErrorLogFile(exp);
			}
			#endregion
		}

		void NetP2PSNDomain_EntsvcPageSetSpecialMsg(string from, string to, string msg, clsPageInfo objPageInfo, string IPAddress)
		{
			try
			{
				bool blnNodePresent = false;

				for (int i = 0; i < lstmyNodes.Count; i++)
				{
					if (lstmyNodes[i].uname == to)
					{
						if (lstmyNodes[i].nodeBType == PeerType.NodeWithHttp)
						{
							clsMessage objmsg = new clsMessage();
							objmsg.strFrom = from;
							objmsg.strTo = new string[] { to };
							objmsg.strMessage = msg;

                            for (int tCnt = 0; tCnt < objPageInfo.objaTabs.Length; tCnt++)
                            {
                                for (int lstCnt = 0; lstCnt < objPageInfo.objaTabs[tCnt].objaPods.Length; lstCnt++)
                                {
                                    string p2puri = objPageInfo.objaTabs[tCnt].objaPods[lstCnt].strUri[0];
                                    string httpuri = "";

                                    System.Reflection.Assembly ass = System.Reflection.Assembly.GetAssembly(typeof(SuperNodeServiceDomain));

                                    ClsPod podObj = new ClsPod();
                                    podObj = ClsPod.GetModInfo(objPageInfo.objaTabs[tCnt].objaPods[lstCnt].intModuleId);

                                    string modulename = podObj.ZipFile.Replace(".zip", "");

                                    string strModPath = ass.Location.Replace("VMukti.Presentation.exe", @"Modules");

                                    string strXmlPath = strModPath + "\\" + modulename + "\\Control\\configuration.xml";

                                    //string[] str = Directory.GetFiles(strXmlPath, ".xml");                    
                                    XmlParser xp = new XmlParser();
                                    xp.Parse(strXmlPath);

                                    #region Loading ReferencedAssemblies

                                    al.Clear();

                                    DirectoryInfo dirinfomodule = new DirectoryInfo(strModPath + "\\" + modulename);
                                    ShowDirectory(dirinfomodule);

                                    for (int j = 0; j < al.Count; j++)
                                    {
                                        string[] arraysplit = al[j].ToString().Split('\\');
                                        if (arraysplit[arraysplit.Length - 1].ToString() == podObj.AssemblyFile)
                                        {
                                            a = Assembly.LoadFrom(al[j].ToString());
                                            AssemblyName[] an = a.GetReferencedAssemblies();

                                            for (int alcount = 0; alcount < al.Count; alcount++)
                                            {
                                                string strsplit = al[alcount].ToString();
                                                string[] strold = strsplit.Split('\\');
                                                string strnew = strold[strold.Length - 1].Substring(0, strold[strold.Length - 1].Length - 4);

                                                for (int asscount = 0; asscount < an.Length; asscount++)
                                                {
                                                    if (an[asscount].Name == strnew)
                                                    {
                                                        Assembly assbal = System.AppDomain.CurrentDomain.Load(System.Reflection.Assembly.LoadFrom(al[alcount].ToString()).GetName());
                                                        AssemblyName[] anbal = assbal.GetReferencedAssemblies();
                                                        for (int andal = 0; andal < al.Count; andal++)
                                                        {
                                                            string strsplitdal = al[andal].ToString();
                                                            string[] strolddal = strsplitdal.Split('\\');
                                                            string strnewdal = strolddal[strolddal.Length - 1].Substring(0, strolddal[strolddal.Length - 1].Length - 4);

                                                            for (int asscountdal = 0; asscountdal < anbal.Length; asscountdal++)
                                                            {
                                                                if (anbal[asscountdal].Name == strnewdal)
                                                                {
                                                                    Assembly assdal = System.AppDomain.CurrentDomain.Load(System.Reflection.Assembly.LoadFrom(al[andal].ToString()).GetName());
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                            Type[] t1 = a.GetTypes();

                                            CopyToBase(modulename, podObj.AssemblyFile);

                                            #region CreatingObject

                                            for (int k = 0; k < t1.Length; k++)
                                            {
                                                if (t1[k].Name == xp.xMain.DummyClassName)
                                                {
                                                    try
                                                    {

                                                        object obj1 = Activator.CreateInstance(t1[k], VMuktiInfo.CurrentPeer.DisplayName);
                                                        MethodInfo mi = t1[k].GetMethod(xp.xMain.DummyMethodName);

                                                        object[] objparams = new object[3];
                                                        objparams[0] = intModule;
                                                        objparams[1] = p2puri;
                                                        objparams[2] = VMuktiInfo.CurrentPeer.SuperNodeIP;
                                                        httpuri = (mi.Invoke(obj1, objparams)).ToString();
                                                    }

                                                    catch (Exception exp)
                                                    {
                                                        MessageBox.Show("Error in creating a dynamic object - " + exp.Message);
                                                    }
                                                }
                                            }
                                            #endregion
                                        }
                                    }
                                    #endregion

                                    objPageInfo.objaTabs[tCnt].objaPods[lstCnt].strUri[1] = httpuri;
                                }
                            }
							//objmsg.lstClsModuleInfo = lstModInfo;
                            objmsg.objPageInfo = objPageInfo;
							//string uri = objModInfo.strUri;
							lstmyNodes[i].lstMyMsgs.Add(objmsg);
							blnNodePresent = true;
							break;
						}
						else
						{
							blnNodePresent = true;
							break;
						}
					}
				}
				if (!blnNodePresent && IPAddress.Substring(0, 1) != "~")
				{
					////clientNetP2pChannelBS.svcSetSpecialMsg(from, to, msg, objModInfo, VMuktiInfo.CurrentPeer.SuperNodeIP);
					//clientNetP2pChannelBS.svcSetSpecialMsg(from, to, msg, lstModInfo, VMuktiAPI.VMuktiInfo.CurrentPeer.SuperNodeIP);
                    clientNetP2pChannelBS.svcSetSpecialMsg(from, to, msg, objPageInfo, VMuktiAPI.VMuktiInfo.CurrentPeer.SuperNodeIP);
				}
			}
			catch (Exception exp)
			{
				exp.Data.Add("My Key", "NetP2PSNDomain_EntsvcPageSetSpecialMsg()--:--SuperNodeServiceDomain.cs--:--" + exp.Message + " :--:--");
				ClsException.LogError(exp);
				ClsException.WriteToErrorLogFile(exp);
			}
		}

		void NetP2PSNDomain_EntsvcAddDraggedBuddy(string from, string to, string msg, clsModuleInfo objModInfo, string IPAddress)
		{

            try
            {
                bool blnIsNodeNotPresent = false;
                for (int BCnt = 0; BCnt < objModInfo.lstUsersDropped.Count; BCnt++) //Dragged Buddy List
                {
                    bool blnNodePresent = false;
                    for (int NCnt = 0; NCnt < lstmyNodes.Count; NCnt++) //Current Node's List
                    {
                        if (objModInfo.lstUsersDropped[BCnt] == lstmyNodes[NCnt].uname)
                        {
                            blnNodePresent = true;
                            if (lstmyNodes[NCnt].nodeBType == PeerType.NodeWithHttp)
                            {
                                clsMessage objMsg = new clsMessage();
                                objMsg.strFrom = to;
                                objMsg.strTo = new string[] { lstmyNodes[NCnt].uname };
                                objMsg.strMessage = "Newly Dragged Buddy";
                                objMsg.objClsModuleInfo = objModInfo;
                                lstmyNodes[NCnt].lstMyMsgs.Add(objMsg);
                                break;
                            }
                        }
                    }
                    if (!blnNodePresent)
                    {
                        blnIsNodeNotPresent = true;
                    }
                }
                if (blnIsNodeNotPresent && IPAddress.Substring(0, 1) != "~")
                {
                    clientNetP2pChannelBS.svcAddDraggedBuddy(from, to, msg, objModInfo, VMuktiAPI.VMuktiInfo.CurrentPeer.SuperNodeIP);
                }
            }
            catch (Exception exp)
            {
                exp.Data.Add("My Key", "NetP2PSNDomain_EntsvcAddDraggedBuddy()--:--SuperNodeServiceDomain.cs--:--" + exp.Message + " :--:--");
                ClsException.LogError(exp);
                ClsException.WriteToErrorLogFile(exp);
            }
		}

		void NetP2PSNDomain_EntsvcAddPageDraggedBuddy(string from, string to, string msg, List<clsModuleInfo> lstModInfo, string IPAddress)
		{
            try
            {
			bool blnIsNodeNotPresent = false;
			for (int BCnt = 0; BCnt < lstModInfo[0].lstUsersDropped.Count; BCnt++) //Dragged Buddy List
			{
				bool blnNodePresent = false;
				for (int NCnt = 0; NCnt < lstmyNodes.Count; NCnt++) //Current Node's List
				{
					if (lstModInfo[0].lstUsersDropped[BCnt] == lstmyNodes[NCnt].uname)
					{
						blnNodePresent = true;
						if (lstmyNodes[NCnt].nodeBType == PeerType.NodeWithHttp)
						{
							clsMessage objMsg = new clsMessage();
							objMsg.strFrom = to;
							objMsg.strTo = new string[] { lstmyNodes[NCnt].uname };
							objMsg.strMessage = "Newly Dragged Buddy";
							objMsg.lstClsModuleInfo = lstModInfo;
							lstmyNodes[NCnt].lstMyMsgs.Add(objMsg);
							break;
						}
					}
				}
				if (!blnNodePresent)
				{
					blnIsNodeNotPresent = true;
				}
			}
			if (blnIsNodeNotPresent && IPAddress.Substring(0, 1) != "~")
			{
				clientNetP2pChannelBS.svcAddDraggedBuddy(from, to, msg, lstModInfo, VMuktiAPI.VMuktiInfo.CurrentPeer.SuperNodeIP);
			}
             }
            catch (Exception exp)
            {
                exp.Data.Add("My Key", "NetP2PSNDomain_EntsvcAddDraggedBuddy()--List--:--SuperNodeServiceDomain.cs--:--" + exp.Message + " :--:--");
                ClsException.LogError(exp);
                ClsException.WriteToErrorLogFile(exp);
            }
		}

        void NetP2PSNDomain_EntsvcSetRemoveDraggedBuddy(string from, List<string> to, string msg, clsModuleInfo objModInfo, string IPAddress)
        {
            try
            {
                #region CLOSE MODULE

                if (msg == "CLOSE MODULE")
                {
                    for (int j = 0; j < to.Count; j++)
                    {
                        bool blnNodePresent = false;
                        for (int i = 0; i < lstmyNodes.Count; i++)
                        {
                            if (lstmyNodes[i].uname == to[j])
                            {
                                if (lstmyNodes[i].nodeBType == PeerType.NodeWithHttp)
                                {
                                    clsMessage objmsg = new clsMessage();
                                    objmsg.strFrom = from;
                                    objmsg.strTo = to.ToArray();
                                    objmsg.strMessage = msg;
                                    string p2puri = null;
                                    string httpuri = null;

                                    objmsg.objClsModuleInfo = objModInfo;
                                    lstmyNodes[i].lstMyMsgs.Add(objmsg);
                                    blnNodePresent = true;
                                    break;
                                }
                                else
                                {
                                    blnNodePresent = true;
                                    //clientNetP2PChannelSN.svcSetRemoveDraggedBuddy(from, to, msg, objModInfo, VMuktiAPI.VMuktiInfo.CurrentPeer.SuperNodeIP);
                                    break;
                                }
                            }
                        }

                        if (!blnNodePresent && IPAddress.Substring(0, 1) != "~")
                        {
                            clientNetP2pChannelBS.svcSetRemoveDraggedBuddy(from, to, msg, objModInfo, VMuktiInfo.CurrentPeer.SuperNodeIP);
                        }
                    }
                }
                #endregion

            }
            catch (Exception exp)
            {
                exp.Data.Add("My Key", "NetP2PSNDomain_EntsvcSetRemoveDraggedBuddy()--:--SuperNodeServiceDomain.cs--:--" + exp.Message + " :--:--");
                ClsException.LogError(exp);
                ClsException.WriteToErrorLogFile(exp);
            }
        }

		#endregion

		#region Buddy Related Function HTTP & NetP2P

		#region HTTP SuperNode Functions

		void SuperNodeServiceDomain_EntHttpsvcjoin(string uName, string bindingType)
		{
			try
			{
				if (bindingType == PeerType.BootStrap.ToString())
				{
					lstmyNodes.Add(new clsNodeInfo(uName, PeerType.BootStrap));
				}
				else if (bindingType == PeerType.SuperNode.ToString())
				{
					lstmyNodes.Add(new clsNodeInfo(uName, PeerType.SuperNode));
				}
				else if (bindingType == PeerType.NodeWithNetP2P.ToString())
				{
					lstmyNodes.Add(new clsNodeInfo(uName, PeerType.NodeWithNetP2P));
				}
				else if (bindingType == PeerType.NodeWithHttp.ToString())
				{
					lstmyNodes.Add(new clsNodeInfo(uName, PeerType.NodeWithHttp));
				}
				if (uName != null && uName != string.Empty)
				{
					fncSNInsertBuddy(uName, "Online");
					fncSNInsertNode(uName);
					fncUpdateUserBuddyStatus(uName, "Online");
				}
				clientNetP2pChannelBS.svcNetP2PAddUser(uName);
			}
			catch (Exception ex)
			{
				ex.Data.Add("My Key", "SuperNodeServiceDomain_EntHttpsvcjoin()--:--SuperNodeDomain.cs--:--" + ex.Message + " :--:--");
				ClsException.LogError(ex);
				ClsException.WriteToErrorLogFile(ex);
			}
		}

		void SuperNodeServiceDomain_EntHttpsvcUnjoin(string uName)
		{
			try
			{
				for (int i = 0; i < lstmyNodes.Count; i++)
				{
					if (lstmyNodes[i].uname == uName)
					{
						lstmyNodes.RemoveAt(i);
						break;
					}
				}
				if (uName != null && uName != string.Empty)
				{
					//   fncSNDeleteBuddy(uName);
					fncSNInsertBuddy(uName, "Offline");
					fncSNDeleteNode(uName);
					fncUpdateUserBuddyStatus(uName, "Offline");
				}
				//channelPeerBootStrap.svcNetP2PRemoveUser(uName);
				clientNetP2pChannelBS.svcNetP2PRemoveUser(uName);

                //remove form hsTable
                if (hsTable.Contains(uName))
                {
                    hsTable.Remove(uName);
                }
                if (lstOfflinebuddies.Remove(uName))
                {
                    lstOfflinebuddies.Remove(uName);
                }
			}
			catch (Exception ex)
			{
				ex.Data.Add("My Key", "SuperNodeServiceDomain_EntHttpsvcUnjoin()--:--SuperNodeDomain.cs--:--" + ex.Message + " :--:--");
				ClsException.LogError(ex);
				ClsException.WriteToErrorLogFile(ex);
			}
		}

		List<string> SuperNodeServiceDomain_EntHttpsvcGetBuddyStatus(List<string> BuddyList)
		{
		//	SqlCeConnection conn = new SqlCeConnection(ClientConnectionString);
		//	conn.Open();
			try
			{
                OpenConnection();
				string str = "SELECT * FROM Node_Status";
				SqlCeDataAdapter dataAdapter = new SqlCeDataAdapter(str, LocalSQLConn);

				DataTable dataTable = new DataTable();
				dataAdapter.Fill(dataTable);
				List<string> lstOnlineBuddies = new List<string>();
				for (int i = 0; i < dataTable.Rows.Count; i++)
				{
					//  lstOnlineBuddies.Add(dataTable.Rows[i][1].ToString());
					lstOnlineBuddies.Add(dataTable.Rows[i][1].ToString() + "-" + dataTable.Rows[i][2].ToString());
				}
				dataAdapter.Dispose();
			//	conn.Close();
			//	conn.Dispose();
				return lstOnlineBuddies;
				//List<string> lstStatus = new List<string>();

				//// Generatig Status List
				//for (int i = 0; i < BuddyList.Count; i++)
				//{
				//    if (lstOnlineBuddies.Contains(BuddyList[i].ToString()))
				//    {
				//        lstStatus.Add("Online");
				//    }
				//    else
				//    {
				//        lstStatus.Add("OffLine");
				//    }
				//}
				//conn.Close();
				//return lstStatus;
			}
			catch (Exception ex)
			{
				ex.Data.Add("My Key", "SuperNodeServiceDomain_EntHttpsvcGetBuddyStatus()--:--SuperNodeDomain.cs--:--" + ex.Message + " :--:--");
				ClsException.LogError(ex);
				ClsException.WriteToErrorLogFile(ex);
			//	conn.Close();
			//	conn.Dispose();

				return null;
			}
		}

        //List<string> SuperNodeServiceDomain_EntHttpGetBuddies(string uName)
        //{

        //    lock (this)
        //    {
        //    //	SqlCeConnection conn = new SqlCeConnection(ClientConnectionString);
				
        //        List<string> lstOnlineBuddies = new List<string>();
        //        try
        //        {
        //            OpenConnection();
        //          //  conn.Open();
        //            string str = "SELECT * FROM User_BuddyList Where UserName ='" + uName + "'";
        //            SqlCeDataAdapter dataAdapter = new SqlCeDataAdapter(str, LocalSQLConn);

        //            DataTable dataTable = new DataTable();
        //            dataAdapter.Fill(dataTable);

        //            for (int i = 0; i < dataTable.Rows.Count; i++)
        //            {
        //                lstOnlineBuddies.Add(dataTable.Rows[i]["BuddyName"].ToString() + "-" + dataTable.Rows[i]["BuddyStatus"].ToString());
        //            }
        //            dataAdapter.Dispose();
        //        //	conn.Close();
        //        //	conn.Dispose();

        //            return lstOnlineBuddies;
        //        }
        //        catch (Exception ex)
        //        {
        //            ex.Data.Add("My Key", "SuperNodeServiceDomain_EntHttpGetBuddies()--:--SuperNodeDomain.cs--:--" + ex.Message + " :--:--");
        //            ClsException.LogError(ex);
        //            ClsException.WriteToErrorLogFile(ex);
        //        //	conn.Close();
        //        //	conn.Dispose();
        //            return lstOnlineBuddies;
        //        }
        //    }
        //}


        //shilpa code
        //12-Feb-2008

        //shilpa code
        //13-Feb-2008

        //Hashtable to maintain the online user
        Hashtable hsTable = new Hashtable();

        //List to maintain the deleted user
        List<string> lstOfflinebuddies = new List<string>();


        List<string> SuperNodeServiceDomain_EntHttpGetBuddies(string uName)
        {
            lock (this)
            {
            //add into hash table if not available
            if (!hsTable.Contains(uName))
            {
                hsTable.Add(uName, DateTime.Now);

                //if lstbox contains the name than inform all
                if (lstOfflinebuddies.Contains(uName))
                {
                    if (uName != null && uName != string.Empty)
                    {
                        fncSNInsertBuddy(uName, "Online");
                        fncSNInsertNode(uName);
                        fncUpdateUserBuddyStatus(uName, "Online");
                    }
                    clientNetP2pChannelBS.svcNetP2PAddUser(uName);
                    //remove from the list
                    lstOfflinebuddies.Remove(uName);

                }

            }
            else
            {
                try
                {
                    //check with previous entry time other
                    IDictionaryEnumerator hsList = hsTable.GetEnumerator();

                    string[] delFromHash = new string[hsTable.Count];
                    int totDel = 0;
                    while (hsList.MoveNext())
                    {
                        //check that the user is requested user or not
                        if (hsList.Key.ToString() != uName)
                        {
                            DateTime previousTime = DateTime.Parse(hsList.Value.ToString());
                            TimeSpan difference = DateTime.Now - previousTime;
                            int TimeInSecond = difference.Seconds;

                            /*
                            //seprate minit hour and second
                            String DelemiStr = ":";
                            char[] delimiter = DelemiStr.ToCharArray();
                            string[] Timelist = difference.ToString().Split(delimiter);

                            //difference in second
                            float TimeInSec = float.Parse(Timelist[2]);

                            //difference in Minit
                            float TimeInMinit = float.Parse(Timelist[1]);

                            //difference in Hour
                            float TimeInHour = float.Parse(Timelist[0]);
                            */
                            //checking of time

                            //if (TimeInHour > 0 || TimeInMinit > 0 || TimeInSec > 15)

                            if (TimeInSecond > 15)
                            {
                                if (hsList.Key.ToString() != null && hsList.Key.ToString() != string.Empty)
                                {
                                    //   fncSNDeleteBuddy(uName);
                                    fncSNInsertBuddy(hsList.Key.ToString(), "Offline");
                                    fncSNDeleteNode(hsList.Key.ToString());
                                    fncUpdateUserBuddyStatus(hsList.Key.ToString(), "Offline");
                                }//end if

                                clientNetP2pChannelBS.svcNetP2PRemoveUser(hsList.Key.ToString());
                                clientHttpChannelBS.svcHttpBSUnJoin(uName,"", false);
                                lstOfflinebuddies.Add(hsList.Key.ToString());
                                //list to delete from hsTable
                                delFromHash[totDel] = hsList.Key.ToString();
                                totDel = totDel + 1;

                            }//end if
                        }//end check req user

                    }//end while

                    //delete form the hashTable
                    if (totDel > 0)
                    {
                        for (int i = 0; i < totDel; i++)
                        {
                            hsTable.Remove(delFromHash[i]);
                        }
                    }
                    //update if still contails into the hash table
                    //update if available
                    if (hsTable.Contains(uName))
                    {
                        hsTable[uName] = DateTime.Now;
                    }
                }
                catch (Exception e)
                {
                    MessageBox.Show(e.ToString());
                }
            }//end else

            //end shilpa code
            //12-Feb-2008

            //shilpa code
            //13-Feb-2008
            
                //SqlCeConnection conn = new SqlCeConnection(ClientConnectionString);
              //  conn.Open();
                List<string> lstOnlineBuddies = new List<string>();
                try
                {
                    string str = "SELECT * FROM User_BuddyList Where UserName ='" + uName + "'";
                    SqlCeDataAdapter dataAdapter = new SqlCeDataAdapter(str, LocalSQLConn);

                    DataTable dataTable = new DataTable();
                    dataAdapter.Fill(dataTable);

                    for (int i = 0; i < dataTable.Rows.Count; i++)
                    {
                        lstOnlineBuddies.Add(dataTable.Rows[i]["BuddyName"].ToString() + "-" + dataTable.Rows[i]["BuddyStatus"].ToString());
                    }
                    dataAdapter.Dispose();
                  //  conn.Close();
                  //  conn.Dispose();

                    return lstOnlineBuddies;
                }
                catch (Exception ex)
                {
                    ex.Data.Add("My Key", "SuperNodeServiceDomain_EntHttpGetBuddies()--:--SuperNodeDomain.cs--:--" + ex.Message + " :--:--");
                    ClsException.LogError(ex);
                    ClsException.WriteToErrorLogFile(ex);
                  //  conn.Close();
                  //  conn.Dispose();
                    return lstOnlineBuddies;
                }
            }
        }


        void SuperNodeServiceDomain_EntHttpAddBuddies(string username, string BuddyName, string BuddyStatus)
        {

            //SqlCeConnection ceConn = new SqlCeConnection(ClientConnectionString);
            //ceConn.Open();
            try
            {
                fncUpdateBuddyStatus(username, BuddyName, BuddyStatus);
                fncUpdateBuddyStatus(BuddyName, username, "Online");
                clientNetP2pChannelBS.svcAddBuddies(username, BuddyName, BuddyStatus);
                clientNetP2pChannelBS.svcAddBuddies(BuddyName, username, "Online");
                //SqlCeCommand sqlcmd = new SqlCeCommand("SELECT Count(*) FROM Node_Status  where Buddy_Name='" + BuddyName + "'", ceConn);
                //object objsqlAddUser = sqlcmd.ExecuteScalar();
                //if (int.Parse(objsqlAddUser.ToString()) > 0)
                //{
                //    SqlCeDataAdapter dataAdapter = new SqlCeDataAdapter("SELECT * FROM Node_Status where Buddy_Name='" + BuddyName + "'", ceConn);
                //    DataTable dataTable = new DataTable();
                //    dataAdapter.Fill(dataTable);
                //    fncUpdateBuddyStatus(username, BuddyName, dataTable.Rows[0][2].ToString());
                //    fncUpdateBuddyStatus(BuddyName, username, "Online");
                //    clientNetP2pChannelBS.svcAddBuddies(username, BuddyName,BuddyStatus);
                //    clientNetP2pChannelBS.svcAddBuddies(BuddyName,username,BuddyStatus);
                //}
                //ceConn.Close();
                //ceConn.Dispose();
            }
            catch (Exception ex)
            {
                //Console.WriteLine("Error In Inserting Value from NodeStatus table on SuperNdoeMachine");
                ex.Data.Add("My Key", "SuperNodeServiceDomain_EntHttpAddBuddies()--:--BootStrapDomain.cs--:--" + ex.Message + " :--:--");
                ClsException.LogError(ex);
                ClsException.WriteToErrorLogFile(ex);
                //ceConn.Close();
                //ceConn.Dispose();

            }
        }

		void SuperNodeServiceDomain_EntHttpRemoveBuddies(string username, string buddyname)
		{
			//SqlCeConnection Conn = new SqlCeConnection(ClientConnectionString);
		//	Conn.Open();
			try
			{
                OpenConnection();
                SqlCeCommand sqlcmd = new SqlCeCommand("delete from User_BuddyList where UserName='" + username + "' and BuddyName='" + buddyname + "'", LocalSQLConn);
				sqlcmd.ExecuteNonQuery();
			//	Conn.Close();
			//	Conn.Dispose();
				clientNetP2pChannelBS.svcRemoveBuddies(username,buddyname);
			}

			catch (Exception ex)
			{

				ex.Data.Add("My Key", "SuperNodeServiceDomain_EntsvcNetP2PRemoveBuddies()--:--Supernodedomain.cs--:--" + ex.Message + " :--:--");
				ClsException.LogError(ex);
				ClsException.WriteToErrorLogFile(ex);
			//	Conn.Close();
			//	Conn.Dispose();
			}

		}
		#endregion

		#region NetP2P SuperNode Functions
		void SuperNodeServiceDomain_EntsvcNetP2PReturnSuperNodeBuddyStatus(string uName, List<string> lstSNBuddyList)
		{
			try
			{
				if (VMuktiInfo.CurrentPeer.DisplayName == uName && blIsSNListPresent == false)
				{
					for (int i = 0; i < lstSNBuddyList.Count; i++)
					{
						fncSNInsertBuddy(lstSNBuddyList[i].ToString(), "Online");
					}
					blIsSNListPresent = true;
				}
			}
			catch (Exception ex)
			{
				ex.Data.Add("My Key", "SuperNodeServiceDomain_EntHttpsvcUnjoin()--:--SuperNodeDomain.cs--:--" + ex.Message + " :--:--");
				ClsException.LogError(ex);
				ClsException.WriteToErrorLogFile(ex);
			}
		}

		void SuperNodeServiceDomain_EntsvcNetP2PReturnBuddyInfo(string uName, List<string> lstMyBuddyList)
		{
			//lock (this)
			//{
			//    if (txtUserName.Text == uName && blBuddyListFound == false)
			//    {
			//        blBuddyListFound = true;
			//        lstFinalMyBuddies = lstMyBuddyList;
			//    }
			//}
		}

		void SuperNodeServiceDomain_EntsvcNetP2PRemoveUser(string uName)
		{
			try
			{
				if (uName != null && uName != string.Empty)
				{
					// fncSNDeleteBuddy(uName);
					fncSNInsertBuddy(uName, "Offline");
					fncSNDeleteNode(uName);
					fncUpdateUserBuddyStatus(uName, "Offline");
				}
			}
			catch (Exception ex)
			{
				ex.Data.Add("My Key", "SuperNodeServiceDomain_EntsvcNetP2PRemoveUser()--:--SuperNodeDomain.cs--:--" + ex.Message + " :--:--");
				ClsException.LogError(ex);
				ClsException.WriteToErrorLogFile(ex);
			}
		}

		void SuperNodeServiceDomain_EntsvcNetP2PGetSuperNodeBuddyStatus(string uName)
		{
			try
			{
				if (VMuktiInfo.CurrentPeer.DisplayName != uName)
				{
					List<string> lsttemp = fncGetOnlineBuddies();
					clientNetP2pChannelBS.svcNetP2PReturnSuperNodeBuddyStatus(uName, lsttemp);
					//channelPeerBootStrap.svcNetP2PReturnSuperNodeBuddyStatus(uName, lsttemp);
				}
			}
			catch (Exception ex)
			{
				ex.Data.Add("My Key", "SuperNodeServiceDomain_EntsvcNetP2PGetSuperNodeBuddyStatus()--:--SuperNodeDomain.cs--:--" + ex.Message + " :--:--");
				ClsException.LogError(ex);
				ClsException.WriteToErrorLogFile(ex);
			}
		}

		void SuperNodeServiceDomain_EntsvcNetP2PGetBuddyInfo(string uName)
		{
			// Meet Code For Buddylist Implementation.

			//string TempPathtoRead = appPath + "\\VMuktiMP_SuperNode_" + uName + "_BuddyList.txt";
			//FileInfo objSuperNodefil = new FileInfo(TempPathtoRead);

			//if (objSuperNodefil.Exists)
			//{
			//    objFileStream = new FileStream(TempPathtoRead, FileMode.OpenOrCreate, FileAccess.ReadWrite);
			//    StreamReader SrReader = new StreamReader(objFileStream);
			//    string strBuddyNameStream = SrReader.ReadToEnd();
			//    strBuddyName = strBuddyNameStream.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries);
			//    SrReader.Close();
			//    objFileStream.Close();
			//    List<string> lstMyBuddies = new List<string>();
			//    for (int i = 0; i < strBuddyName.Length; i++)
			//    {
			//        lstMyBuddies.Add(strBuddyName[i]);
			//    }
			// clientNetP2pChannelBS.svcNetP2PReturnBuddyInfo(uName, lstMyBuddies);
			//
			SqlCeConnection conn = new SqlCeConnection(ClientConnectionString);
			conn.Open();
			try
			{

				string str = "SELECT * FROM Node_Status";
				SqlCeDataAdapter dataAdapter = new SqlCeDataAdapter(str, conn);

				DataTable dataTable = new DataTable();
				dataAdapter.Fill(dataTable);
				List<string> lstOnlineBuddies = new List<string>();
				for (int i = 0; i < dataTable.Rows.Count; i++)
				{
					lstOnlineBuddies.Add(dataTable.Rows[i][1].ToString());
				}
				//channelPeerBootStrap.svcNetP2PReturnBuddyInfo(uName, lstMyBuddies);
				conn.Close();
				conn.Dispose();
				clientNetP2pChannelBS.svcNetP2PReturnBuddyInfo(uName, lstOnlineBuddies);
				// End Meet Code.
			}
			catch (Exception ex)
			{
				ex.Data.Add("My Key", "SuperNodeServiceDomain_EntsvcNetP2PGetBuddyInfo()--:--SuperNodeDomain.cs--:--" + ex.Message + " :--:--");
				ClsException.LogError(ex);
				ClsException.WriteToErrorLogFile(ex);
				conn.Close();
				conn.Dispose();
			}
		}

		void SuperNodeServiceDomain_EntsvcNetP2PAddUser(string uName)
		{
			try
			{
				if (uName != null && uName != string.Empty)
				{
					fncSNInsertBuddy(uName, "Online");
					fncUpdateUserBuddyStatus(uName, "Online");
				}
			}
			catch (Exception ex)
			{
				ex.Data.Add("My Key", "SuperNodeServiceDomain_EntsvcNetP2PAddUser()--:--SuperNodeDomain.cs--:--" + ex.Message + " :--:--");
				ClsException.LogError(ex);
				ClsException.WriteToErrorLogFile(ex);
			}
		}

        void SuperNodeServiceDomain_EntsvcNetP2PAddBuddies(string username, string BuddyName, string BuddyStatus)
        {
            //SqlCeConnection ceConn = new SqlCeConnection(ClientConnectionString);
            //ceConn.Open();
            try
            {
                fncUpdateBuddyStatus(username, BuddyName, BuddyStatus);
                //SqlCeCommand sqlcmd = new SqlCeCommand("SELECT Count(*) FROM Node_Status  where Buddy_Name='" + BuddyName + "'", ceConn);
                //object objsqlAddUser = sqlcmd.ExecuteScalar();
                //if (int.Parse(objsqlAddUser.ToString()) > 0)
                //{
                //    SqlCeDataAdapter dataAdapter = new SqlCeDataAdapter("SELECT * FROM Node_Status where Buddy_Name='" + BuddyName + "'", ceConn);
                //    DataTable dataTable = new DataTable();
                //    dataAdapter.Fill(dataTable);
                //    ceConn.Close();
                //    ceConn.Dispose();
                //    fncUpdateBuddyStatus(username, BuddyName, dataTable.Rows[0][2].ToString());
                //}
            }
            catch (Exception ex)
            {
                //Console.WriteLine("Error In Inserting Value from NodeStatus table on SuperNdoeMachine");
                ex.Data.Add("My Key", "SuperNodeServiceDomain_EntsvcNetP2PAddBuddies()--:--BootStrapDomain.cs--:--" + ex.Message + " :--:--");
                ClsException.LogError(ex);
                ClsException.WriteToErrorLogFile(ex);
                //ceConn.Close();
                //ceConn.Dispose();
            }
        }

		void SuperNodeServiceDomain_EntsvcNetP2PRemoveBuddies(string username, string BuddyName)
		{
			SqlCeConnection Conn = new SqlCeConnection(ClientConnectionString);
			Conn.Open();
			try
			{
				SqlCeCommand sqlcmd = new SqlCeCommand("delete from User_BuddyList where UserName='" + username + "' and BuddyName='" + BuddyName + "'", Conn);				
				sqlcmd.ExecuteNonQuery();
				Conn.Close();
				Conn.Dispose();				
			}
			
			catch (Exception ex)
			{
				
				ex.Data.Add("My Key", "SuperNodeServiceDomain_EntsvcNetP2PRemoveBuddies()--:--Supernodedomain.cs--:--" + ex.Message + " :--:--");
				ClsException.LogError(ex);
				ClsException.WriteToErrorLogFile(ex);
				Conn.Close();
				Conn.Dispose();
			}
		}

		#endregion


		#endregion

		#region Http SuperNode Events Handlers

		string[] SuperNodeServiceDomain_EntsvcStartAService(VMuktiAPI.PeerType PeerType, string ModId)
		{
			string p2puri = "";
			string httpuri = "";
			try
			{
				//npsModules.Add(new NetPeerServer("net.tcp://" + VMuktiInfo.CurrentPeer.SuperNodeIP + ":400" + intModule.ToString() + "/" + intModule.ToString()));
				//npsModules[npsModules.Count - 1].AddEndPoint("net.tcp://" + VMuktiInfo.CurrentPeer.SuperNodeIP + ":400" + intModule.ToString() + "/" + intModule.ToString());
				//npsModules[npsModules.Count - 1].Name = "net.tcp://" + VMuktiInfo.CurrentPeer.SuperNodeIP + ":400" + intModule.ToString() + "/" + intModule.ToString();
				//npsModules[npsModules.Count - 1].OpenServer();

				//p2puri = "net.tcp://" + VMuktiInfo.CurrentPeer.SuperNodeIP + ":400" + intModule.ToString() + "/" + intModule.ToString();

				DateTime TimeStamp = DateTime.Now.ToUniversalTime();

				//MessageBox.Show(TimeStampIp.ToString());

				string TimeStampIp = TimeStamp.ToString().Replace(":", "").Replace("/", "").Replace(" ", "").Replace("AM", "").Replace("PM", "") + TimeStamp.Millisecond.ToString() + VMuktiAPI.VMuktiInfo.CurrentPeer.SuperNodeIP;

				npsModules.Add(new NetPeerServer("net.tcp://" + VMuktiInfo.CurrentPeer.SuperNodeIP + ":400" + intModule.ToString() + "/" + TimeStampIp));
				npsModules[npsModules.Count - 1].AddEndPoint("net.tcp://" + VMuktiInfo.CurrentPeer.SuperNodeIP + ":400" + intModule.ToString() + "/" + TimeStampIp);
				npsModules[npsModules.Count - 1].Name = "net.tcp://" + VMuktiInfo.CurrentPeer.SuperNodeIP + ":400" + intModule.ToString() + "/" + TimeStampIp;
				npsModules[npsModules.Count - 1].OpenServer();

				p2puri = "net.tcp://" + VMuktiInfo.CurrentPeer.SuperNodeIP + ":400" + intModule.ToString() + "/" + TimeStampIp;

				
				if (PeerType == PeerType.NodeWithHttp)
				{
					System.Reflection.Assembly ass = System.Reflection.Assembly.GetAssembly(typeof(SuperNodeServiceDomain));

					ClsPod podObj = new ClsPod();
					podObj = ClsPod.GetModInfo(int.Parse(ModId));

					string modulename = podObj.ZipFile.Replace(".zip", "");

					string strModPath = ass.Location.Replace("VMukti.Presentation.exe", @"Modules");

					string strXmlPath = strModPath + "\\" + modulename + "\\Control\\configuration.xml";

					//string[] str = Directory.GetFiles(strXmlPath, ".xml");                    
					XmlParser xp = new XmlParser();
					xp.Parse(strXmlPath);

					#region Loading ReferencedAssemblies

					al.Clear();

					DirectoryInfo dirinfomodule = new DirectoryInfo(strModPath + "\\" + modulename);
					ShowDirectory(dirinfomodule);

					for (int j = 0; j < al.Count; j++)
					{
						string[] arraysplit = al[j].ToString().Split('\\');
						if (arraysplit[arraysplit.Length - 1].ToString() == podObj.AssemblyFile)
						{
							a = Assembly.LoadFrom(al[j].ToString());
							AssemblyName[] an = a.GetReferencedAssemblies();

							for (int alcount = 0; alcount < al.Count; alcount++)
							{
								string strsplit = al[alcount].ToString();
								string[] strold = strsplit.Split('\\');
								string strnew = strold[strold.Length - 1].Substring(0, strold[strold.Length - 1].Length - 4);

								for (int asscount = 0; asscount < an.Length; asscount++)
								{
									if (an[asscount].Name == strnew)
									{
										Assembly assbal = System.AppDomain.CurrentDomain.Load(System.Reflection.Assembly.LoadFrom(al[alcount].ToString()).GetName());

										AssemblyName[] anbal = assbal.GetReferencedAssemblies();
										for (int andal = 0; andal < al.Count; andal++)
										{
											string strsplitdal = al[andal].ToString();
											string[] strolddal = strsplitdal.Split('\\');
											string strnewdal = strolddal[strolddal.Length - 1].Substring(0, strolddal[strolddal.Length - 1].Length - 4);

											for (int asscountdal = 0; asscountdal < anbal.Length; asscountdal++)
											{
												if (anbal[asscountdal].Name == strnewdal)
												{
													Assembly assdal = System.AppDomain.CurrentDomain.Load(System.Reflection.Assembly.LoadFrom(al[andal].ToString()).GetName());
													//CopyToBase(modulename, System.Reflection.Assembly.LoadFrom(al[andal].ToString()).GetName().ToString());
												}
											}
										}
									}
								}
							}
							Type[] t1 = a.GetTypes();

							CopyToBase(modulename, podObj.AssemblyFile);

							#region CreatingObject

							for (int k = 0; k < t1.Length; k++)
							{
								if (t1[k].Name == xp.xMain.DummyClassName)
								{
									try
									{

										object obj1 = Activator.CreateInstance(t1[k], VMuktiInfo.CurrentPeer.DisplayName);
										MethodInfo mi = t1[k].GetMethod(xp.xMain.DummyMethodName);

										object[] objparams = new object[3];
										objparams[0] = intModule;
										objparams[1] = p2puri;
										objparams[2] = VMuktiInfo.CurrentPeer.SuperNodeIP;
										httpuri = (mi.Invoke(obj1, objparams)).ToString();
									}

									catch (Exception exp)
									{
										MessageBox.Show("CreatingObject " + exp.Message);
									}
								}
							}
							#endregion


						}
					}
					#endregion

				}
				
				intModule++;
				return new string[] { p2puri, httpuri };
			}
			catch (Exception exp)
			{
                exp.Data.Add("My Key", "SuperNodeServiceDomain_EntsvcStartAService()--1--:--SuperNodeServiceDomain.cs--:--" + exp.Message + " :--:--");
                ClsException.LogError(exp);
                ClsException.WriteToErrorLogFile(exp);
				if (exp.InnerException != null)
				{
					//MessageBox.Show(exp.InnerException.Message);
                    exp.Data.Add("My Key", "SuperNodeServiceDomain_EntsvcStartAService()--2--:--SuperNodeServiceDomain.cs--:--" + exp.InnerException.Message + " :--:--");
                    ClsException.LogError(exp);
                    ClsException.WriteToErrorLogFile(exp);
				}

				return null;
			}
		}

        void SuperNodeServiceDomain_EntsvcSetSpecialMsg(string from, string to, string msg, clsModuleInfo objModInfo)
        {
            try
            {

                #region OPEN MODULE


                bool blnNodePresent = false;

                for (int i = 0; i < lstmyNodes.Count; i++)
                {
                    if (lstmyNodes[i].uname == to)
                    {
                        if (lstmyNodes[i].nodeBType == PeerType.NodeWithHttp)
                        {
                            clsMessage objmsg = new clsMessage();
                            objmsg.strFrom = from;
                            objmsg.strTo = new string[] { to };
                            objmsg.strMessage = msg;
                            string p2puri = objModInfo.strUri[0];
                            string httpuri = "";

                            System.Reflection.Assembly ass = System.Reflection.Assembly.GetAssembly(typeof(SuperNodeServiceDomain));

                            ClsPod podObj = new ClsPod();
                            podObj = ClsPod.GetModInfo(objModInfo.intModuleId);

                            string modulename = podObj.ZipFile.Replace(".zip", "");

                            string strModPath = ass.Location.Replace("VMukti.Presentation.exe", @"Modules");

                            string strXmlPath = strModPath + "\\" + modulename + "\\Control\\configuration.xml";

                            //string[] str = Directory.GetFiles(strXmlPath, ".xml");                    
                            XmlParser xp = new XmlParser();
                            xp.Parse(strXmlPath);

                            #region Loading ReferencedAssemblies

                            al.Clear();

                            DirectoryInfo dirinfomodule = new DirectoryInfo(strModPath + "\\" + modulename);
                            ShowDirectory(dirinfomodule);

                            for (int j = 0; j < al.Count; j++)
                            {
                                string[] arraysplit = al[j].ToString().Split('\\');
                                if (arraysplit[arraysplit.Length - 1].ToString() == podObj.AssemblyFile)
                                {
                                    a = Assembly.LoadFrom(al[j].ToString());
                                    AssemblyName[] an = a.GetReferencedAssemblies();

                                    for (int alcount = 0; alcount < al.Count; alcount++)
                                    {
                                        string strsplit = al[alcount].ToString();
                                        string[] strold = strsplit.Split('\\');
                                        string strnew = strold[strold.Length - 1].Substring(0, strold[strold.Length - 1].Length - 4);

                                        for (int asscount = 0; asscount < an.Length; asscount++)
                                        {
                                            if (an[asscount].Name == strnew)
                                            {
                                                Assembly assbal = System.AppDomain.CurrentDomain.Load(System.Reflection.Assembly.LoadFrom(al[alcount].ToString()).GetName());
                                                AssemblyName[] anbal = assbal.GetReferencedAssemblies();
                                                for (int andal = 0; andal < al.Count; andal++)
                                                {
                                                    string strsplitdal = al[andal].ToString();
                                                    string[] strolddal = strsplitdal.Split('\\');
                                                    string strnewdal = strolddal[strolddal.Length - 1].Substring(0, strolddal[strolddal.Length - 1].Length - 4);

                                                    for (int asscountdal = 0; asscountdal < anbal.Length; asscountdal++)
                                                    {
                                                        if (anbal[asscountdal].Name == strnewdal)
                                                        {
                                                            Assembly assdal = System.AppDomain.CurrentDomain.Load(System.Reflection.Assembly.LoadFrom(al[andal].ToString()).GetName());
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                    Type[] t1 = a.GetTypes();

                                    CopyToBase(modulename, podObj.AssemblyFile);

                                    #region CreatingObject

                                    for (int k = 0; k < t1.Length; k++)
                                    {
                                        if (t1[k].Name == xp.xMain.DummyClassName)
                                        {
                                            try
                                            {

                                                object obj1 = Activator.CreateInstance(t1[k], VMuktiInfo.CurrentPeer.DisplayName);
                                                MethodInfo mi = t1[k].GetMethod(xp.xMain.DummyMethodName);

                                                object[] objparams = new object[3];
                                                objparams[0] = intModule;
                                                objparams[1] = p2puri;
                                                objparams[2] = VMuktiInfo.CurrentPeer.SuperNodeIP;
                                                httpuri = (mi.Invoke(obj1, objparams)).ToString();
                                            }

                                            catch (Exception exp)
                                            {
                                                MessageBox.Show("CreatingObject " + exp.Message);
                                            }
                                        }
                                    }
                                    #endregion
                                }
                            }
                            #endregion

                            objModInfo.strUri[1] = httpuri;
                            objmsg.objClsModuleInfo = objModInfo;
                            lstmyNodes[i].lstMyMsgs.Add(objmsg);
                            blnNodePresent = true;
                            al.Clear();
                            break;
                        }
                        else
                        {
                            blnNodePresent = true;
                            clientNetP2PChannelSN.svcSetSpecialMsg(from, to, msg, objModInfo, VMuktiInfo.CurrentPeer.SuperNodeIP);
                        }
                    }
                }
                if (!blnNodePresent)
                {
                    clientNetP2pChannelBS.svcSetSpecialMsg(from, to, msg, objModInfo, VMuktiInfo.CurrentPeer.SuperNodeIP);
                }


                #endregion
            }
            catch (Exception exp)
            {
                exp.Data.Add("My Key", "SuperNodeServiceDomain_EntsvcSetSpecialMsg()--:--SuperNodeServiceDomain.cs--:--" + exp.Message + " :--:--");
                ClsException.LogError(exp);
                ClsException.WriteToErrorLogFile(exp);
            }
        }

        void SuperNodeServiceDomain_EntsvcPageSetSpecialMsg(string from, string to, string msg, clsPageInfo objPageInfo)
        {
            try
            {
                bool blnNodePresent = false;

                for (int i = 0; i < lstmyNodes.Count; i++)
                {
                    if (lstmyNodes[i].uname == to)
                    {
                        if (lstmyNodes[i].nodeBType == PeerType.NodeWithHttp)
                        {
                            clsMessage objmsg = new clsMessage();
                            objmsg.strFrom = from;
                            objmsg.strTo = new string[] { to };
                            objmsg.strMessage = msg;

                            for (int tCnt = 0; tCnt < objPageInfo.objaTabs.Length; tCnt++)
                            {
                                for (int lstCnt = 0; lstCnt < objPageInfo.objaTabs[tCnt].objaPods.Length; lstCnt++)
                                {
                                    string p2puri = objPageInfo.objaTabs[tCnt].objaPods[lstCnt].strUri[0];
                                    string httpuri = "";

                                    System.Reflection.Assembly ass = System.Reflection.Assembly.GetAssembly(typeof(SuperNodeServiceDomain));

                                    ClsPod podObj = new ClsPod();
                                    podObj = ClsPod.GetModInfo(objPageInfo.objaTabs[tCnt].objaPods[lstCnt].intModuleId);

                                    string modulename = podObj.ZipFile.Replace(".zip", "");

                                    string strModPath = ass.Location.Replace("VMukti.Presentation.exe", @"Modules");

                                    string strXmlPath = strModPath + "\\" + modulename + "\\Control\\configuration.xml";

                                    //string[] str = Directory.GetFiles(strXmlPath, ".xml");                    
                                    XmlParser xp = new XmlParser();
                                    xp.Parse(strXmlPath);

                                    #region Loading ReferencedAssemblies

                                    al.Clear();

                                    DirectoryInfo dirinfomodule = new DirectoryInfo(strModPath + "\\" + modulename);
                                    ShowDirectory(dirinfomodule);

                                    for (int j = 0; j < al.Count; j++)
                                    {
                                        string[] arraysplit = al[j].ToString().Split('\\');
                                        if (arraysplit[arraysplit.Length - 1].ToString() == podObj.AssemblyFile)
                                        {
                                            a = Assembly.LoadFrom(al[j].ToString());
                                            AssemblyName[] an = a.GetReferencedAssemblies();

                                            for (int alcount = 0; alcount < al.Count; alcount++)
                                            {
                                                string strsplit = al[alcount].ToString();
                                                string[] strold = strsplit.Split('\\');
                                                string strnew = strold[strold.Length - 1].Substring(0, strold[strold.Length - 1].Length - 4);

                                                for (int asscount = 0; asscount < an.Length; asscount++)
                                                {
                                                    if (an[asscount].Name == strnew)
                                                    {
                                                        Assembly assbal = System.AppDomain.CurrentDomain.Load(System.Reflection.Assembly.LoadFrom(al[alcount].ToString()).GetName());
                                                        AssemblyName[] anbal = assbal.GetReferencedAssemblies();
                                                        for (int andal = 0; andal < al.Count; andal++)
                                                        {
                                                            string strsplitdal = al[andal].ToString();
                                                            string[] strolddal = strsplitdal.Split('\\');
                                                            string strnewdal = strolddal[strolddal.Length - 1].Substring(0, strolddal[strolddal.Length - 1].Length - 4);

                                                            for (int asscountdal = 0; asscountdal < anbal.Length; asscountdal++)
                                                            {
                                                                if (anbal[asscountdal].Name == strnewdal)
                                                                {
                                                                    Assembly assdal = System.AppDomain.CurrentDomain.Load(System.Reflection.Assembly.LoadFrom(al[andal].ToString()).GetName());
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                            Type[] t1 = a.GetTypes();

                                            CopyToBase(modulename, podObj.AssemblyFile);

                                            #region CreatingObject

                                            for (int k = 0; k < t1.Length; k++)
                                            {
                                                if (t1[k].Name == xp.xMain.DummyClassName)
                                                {
                                                    try
                                                    {

                                                        object obj1 = Activator.CreateInstance(t1[k], VMuktiInfo.CurrentPeer.DisplayName);
                                                        MethodInfo mi = t1[k].GetMethod(xp.xMain.DummyMethodName);

                                                        object[] objparams = new object[3];
                                                        objparams[0] = intModule;
                                                        objparams[1] = p2puri;
                                                        objparams[2] = VMuktiInfo.CurrentPeer.SuperNodeIP;
                                                        httpuri = (mi.Invoke(obj1, objparams)).ToString();
                                                    }

                                                    catch (Exception exp)
                                                    {
                                                        MessageBox.Show("CreatingObject " + exp.Message);
                                                    }
                                                }
                                            }
                                            #endregion
                                        }
                                    }
                                    #endregion
                                    objPageInfo.objaTabs[tCnt].objaPods[lstCnt].strUri[1] = httpuri;
                                }
                            }
                            objmsg.objPageInfo = objPageInfo;
                            //objmsg.lstClsModuleInfo = objModInfo;
                            //objmsg.objClsModuleInfo = objModInfo;
                            lstmyNodes[i].lstMyMsgs.Add(objmsg);
                            blnNodePresent = true;
                            al.Clear();
                            break;
                        }
                        else
                        {
                            blnNodePresent = true;
                            ////clientNetP2PChannelSN.svcSetSpecialMsg(from, to, msg, objModInfo, VMuktiInfo.CurrentPeer.SuperNodeIP);
                            //clientNetP2PChannelSN.svcSetSpecialMsg(from, to, msg, objModInfo, VMuktiAPI.VMuktiInfo.CurrentPeer.SuperNodeIP);
                            clientNetP2PChannelSN.svcSetSpecialMsg(from, to, msg, objPageInfo, VMuktiAPI.VMuktiInfo.CurrentPeer.SuperNodeIP);
                        }
                    }
                }
                if (!blnNodePresent)
                {
                    ////clientNetP2pChannelBS.svcSetSpecialMsg(from, to, msg, objModInfo, VMuktiInfo.CurrentPeer.SuperNodeIP);
                    //clientNetP2pChannelBS.svcSetSpecialMsg(from, to, msg, objModInfo, VMuktiInfo.CurrentPeer.SuperNodeIP);
                    clientNetP2pChannelBS.svcSetSpecialMsg(from, to, msg, objPageInfo, VMuktiInfo.CurrentPeer.SuperNodeIP);
                }
            }
            catch (Exception exp)
            {
                exp.Data.Add("My Key", "SuperNodeServiceDomain_EntsvcPageSetSpecialMsg()--:--SuperNodeServiceDomain.cs--:--" + exp.Message + " :--:--");
                ClsException.LogError(exp);
                ClsException.WriteToErrorLogFile(exp);
            }

        }

		void SuperNodeServiceDomain_EntsvcAddDraggedBuddy(string from, string to, string msg, clsModuleInfo objModInfo)
		{
            try
            {
                bool blnIsNodeNotPresent = false;
                for (int BCnt = 0; BCnt < objModInfo.lstUsersDropped.Count; BCnt++) //Dragged Buddy List
                {
                    bool blnNodePresent = false;
                    for (int NCnt = 0; NCnt < lstmyNodes.Count; NCnt++) //Current Node's List
                    {
                        if (objModInfo.lstUsersDropped[BCnt] == lstmyNodes[NCnt].uname)
                        {
                            blnNodePresent = true;
                            if (lstmyNodes[NCnt].nodeBType == PeerType.NodeWithHttp)
                            {
                                clsMessage objMsg = new clsMessage();
                                objMsg.strFrom = to;
                                objMsg.strTo = new string[] { lstmyNodes[NCnt].uname };
                                objMsg.strMessage = "Newly Dragged Buddy";
                                objMsg.objClsModuleInfo = objModInfo;
                                lstmyNodes[NCnt].lstMyMsgs.Add(objMsg);
                                break;
                            }
                            else
                            {
                                clientNetP2PChannelSN.svcAddDraggedBuddy(from, to, msg, objModInfo, VMuktiInfo.CurrentPeer.SuperNodeIP);
                            }
                        }
                    }
                    if (!blnNodePresent)
                    {
                        blnIsNodeNotPresent = true;
                    }
                }
                if (blnIsNodeNotPresent)
                {
                    clientNetP2pChannelBS.svcAddDraggedBuddy(from, to, msg, objModInfo, VMuktiAPI.VMuktiInfo.CurrentPeer.SuperNodeIP);
                }
            }
            catch (Exception exp)
            {
                exp.Data.Add("My Key", "SuperNodeServiceDomain_EntsvcAddDraggedBuddy()--:--SuperNodeServiceDomain.cs--:--" + exp.Message + " :--:--");
                ClsException.LogError(exp);
                ClsException.WriteToErrorLogFile(exp);
            }

		}

		void SuperNodeServiceDomain_EntsvcAddPageDraggedBuddy(string from, string to, string msg, List<clsModuleInfo> objModInfo)
		{
            try
            {
                bool blnIsNodeNotPresent = false;
                for (int BCnt = 0; BCnt < objModInfo[0].lstUsersDropped.Count; BCnt++) //Dragged Buddy List
                {
                    bool blnNodePresent = false;
                    for (int NCnt = 0; NCnt < lstmyNodes.Count; NCnt++) //Current Node's List
                    {
                        if (objModInfo[0].lstUsersDropped[BCnt] == lstmyNodes[NCnt].uname)
                        {
                            blnNodePresent = true;
                            if (lstmyNodes[NCnt].nodeBType == PeerType.NodeWithHttp)
                            {
                                clsMessage objMsg = new clsMessage();
                                objMsg.strFrom = to;
                                objMsg.strTo = new string[] { lstmyNodes[NCnt].uname };
                                objMsg.strMessage = "Newly Dragged Buddy";
                                objMsg.lstClsModuleInfo = objModInfo;
                                lstmyNodes[NCnt].lstMyMsgs.Add(objMsg);
                                break;
                            }
                            else
                            {
                                clientNetP2PChannelSN.svcAddDraggedBuddy(from, to, msg, objModInfo, VMuktiInfo.CurrentPeer.SuperNodeIP);
                            }
                        }
                    }
                    if (!blnNodePresent)
                    {
                        blnIsNodeNotPresent = true;
                    }
                }
                if (blnIsNodeNotPresent)
                {
                    clientNetP2pChannelBS.svcAddDraggedBuddy(from, to, msg, objModInfo, VMuktiAPI.VMuktiInfo.CurrentPeer.SuperNodeIP);
                }
            }
            
            catch (Exception exp)
            {
                exp.Data.Add("My Key", "SuperNodeServiceDomain_EntsvcAddPageDraggedBuddy()--2--:--SuperNodeServiceDomain.cs--:--" + exp.Message + " :--:--");
                ClsException.LogError(exp);
                ClsException.WriteToErrorLogFile(exp);
            }
		}

		void SuperNodeServiceDomain_EntsvcSetRemoveDraggedBuddy(string from, List<string> to, string msg, clsModuleInfo objModInfo)
		{
             try
            {
			#region CLOSE MODULE

			if (msg == "CLOSE MODULE")
			{
				for (int j = 0; j < to.Count; j++)
				{
					bool blnNodePresent = false;
					for (int i = 0; i < lstmyNodes.Count; i++)
					{
						if (lstmyNodes[i].uname == to[j])
						{
							if (lstmyNodes[i].nodeBType == PeerType.NodeWithHttp)
							{
								clsMessage objmsg = new clsMessage();
								objmsg.strFrom = from;
								objmsg.strTo = to.ToArray();
								objmsg.strMessage = msg;
								string p2puri = null;
								string httpuri = null;

								objmsg.objClsModuleInfo = objModInfo;
								lstmyNodes[i].lstMyMsgs.Add(objmsg);
								blnNodePresent = true;
								break;
							}
							else
							{
								blnNodePresent = true;
								clientNetP2PChannelSN.svcSetRemoveDraggedBuddy(from, to, msg, objModInfo, VMuktiInfo.CurrentPeer.SuperNodeIP);
								break;
							}
						}
					}

					if (!blnNodePresent)
					{
						clientNetP2pChannelBS.svcSetRemoveDraggedBuddy(from, to, msg, objModInfo, VMuktiInfo.CurrentPeer.SuperNodeIP);
					}


				}

			}

			#endregion
             }
            catch (Exception exp)
            {
                exp.Data.Add("My Key", "SuperNodeServiceDomain_EntsvcSetRemoveDraggedBuddy()--:--SuperNodeServiceDomain.cs--:--" + exp.Message + " :--:--");
                ClsException.LogError(exp);
                ClsException.WriteToErrorLogFile(exp);
            }
		}

        List<VMukti.Business.CommonDataContracts.clsMessage> SuperNodeServiceDomain_EntsvcGetSpecialMsgs(string uName)
        {
            try
            {
                lock (this)
                {
                    List<clsMessage> tmpMsg = new List<clsMessage>();
                    for (int i = 0; i < lstmyNodes.Count; i++)
                    {
                        if (lstmyNodes[i].uname == uName)
                        {
                            for (int j = 0; j < lstmyNodes[i].lstMyMsgs.Count; j++)
                            {
                                tmpMsg.Add(lstmyNodes[i].lstMyMsgs[j]);
                                lstmyNodes[i].lstMyMsgs.RemoveAt(j);
                            }
                            break;
                        }
                    }
                    return tmpMsg;
                }
            }
            catch (Exception exp)
            {
                exp.Data.Add("My Key", "SuperNodeServiceDomain_EntsvcGetSpecialMsgs()--:--SuperNodeServiceDomain.cs--:--" + exp.Message + " :--:--");
                ClsException.LogError(exp);
                ClsException.WriteToErrorLogFile(exp);
                return null;
            }
        }

		bool SuperNodeServiceDomain_EntIsSuperNodeAvailable()
		{
			return true;
		}

		string[] SuperNodeServiceDomain_EntIsAuthorizedUser(clsBootStrapInfo objBootStrapInfo, string strUserName, string strPassword)
		{
			try
			{
				bool AuthResult = false;
				VMukti.Business.ClsUser CurrenUser = null;

				if (objBootStrapInfo.AuthType == VMuktiAPI.AuthType.SQLAuthentication.ToString())
				{
					VMuktiAPI.VMuktiInfo.MainConnectionString = objBootStrapInfo.ConnectionString;

					CurrenUser = VMukti.Business.ClsUser.GetByUNamePass(strUserName, strPassword, ref AuthResult);
					if (CurrenUser == null)
					{
						if (AuthResult)
						{
							return new string[] { "WrongPassword" };
						}
						else
						{
							return new string[] { "WrongUserName" };
						}
					}
					else
					{
						List<string> UserInfo = new List<string>();
						UserInfo.Add("ID=" + CurrenUser.ID.ToString());
						UserInfo.Add("DisplayName=" + CurrenUser.DisplayName.ToString());
						UserInfo.Add("RoleID=" + CurrenUser.RoleID.ToString());
						UserInfo.Add("FName=" + CurrenUser.FName.ToString());
						UserInfo.Add("LName=" + CurrenUser.LName.ToString());
						UserInfo.Add("EMail=" + CurrenUser.EMail.ToString());
						UserInfo.Add("PassWord=" + CurrenUser.PassWord.ToString());
                        UserInfo.Add("IsActive=" + CurrenUser.IsActive.ToString());
                        UserInfo.Add("Status=Online");
                        UserInfo.Add("RoleName="+CurrenUser.RoleName.ToString());

						fncSNInsertBuddy(CurrenUser.DisplayName.ToString(), "Online");
						fncSNInsertNode(CurrenUser.DisplayName.ToString());
						fncUpdateUserBuddyStatus(CurrenUser.DisplayName.ToString(), "Online");
						clientNetP2pChannelBS.svcNetP2PAddUser(CurrenUser.DisplayName.ToString());

						try
						{
							bool blnNodePresent = false;
							for (int lstCnt = 0; lstCnt < lstmyNodes.Count; lstCnt++)
							{
								if (lstmyNodes[lstCnt].uname == CurrenUser.DisplayName)
								{
									blnNodePresent = true;
									break;
								}
							}
							if (!blnNodePresent)
							{
								lstmyNodes.Add(new clsNodeInfo(CurrenUser.DisplayName, PeerType.NodeWithHttp));
							}
						}
						catch (Exception ex)
						{
							ex.Data.Add("My Key", "SuperNodeServiceDomain_EntHttpsvcjoin()--:--SuperNodeDomain.cs--:--" + ex.Message + " :--:--");
							ClsException.LogError(ex);
							ClsException.WriteToErrorLogFile(ex);
						}


						return UserInfo.ToArray();
						//((Page)((ScrollViewer)((Canvas)this.Parent).Parent).Parent).NavigationService.Navigate(new Uri("pgHome.xaml", UriKind.RelativeOrAbsolute));
						//LoginService.svcUnJoin(txtUserNameID.Text);
						//LoginService.Close();
					}
				}
				else if (objBootStrapInfo.AuthType == VMuktiAPI.AuthType.SIPAuthentication.ToString())
				{
					lstObjRTCAuthClient.Add(new clsRTCAuthClient(objBootStrapInfo.SIPUserNumber, strPassword, objBootStrapInfo.AuthServerIP));
					return new string[] { "CheckStatus" };
				}
				else
				{
					return null;
				}
			}
			catch (Exception ex)
			{
				MessageBox.Show(ex.Message);
				return null;
			}
		}

		string SuperNodeServiceDomain_EntIsAuthorized(string strUserName)
		{
			return null;
			//for (int i = 0; i < lstObjRTCAuthClient.Count; i++)
			//{
			//    return null;
			//}
		}

		string SuperNodeServiceDomain_EntsvcAddSIPUser()
		{
			return objPBX.FncCreateSIPUser();
		}

		string SuperNodeServiceDomain_EntsvcGetConferenceNumber()
		{
			return objPBX.FncCreateConference();
		}

		void SuperNodeServiceDomain_EntsvcRemoveSIPUser(string strSIPNumber)
		{
			objPBX.FncRemoveSIPUser(strSIPNumber);
		}
		#endregion

		#region DataBase Creation Function
        //public string ClientConnectionString = @"Data Source=" + AppDomain.CurrentDomain.BaseDirectory + "SuperNodeBuddyInfo.sdf";
        //public string strLocalDBPath;

		public void fncCreateBuddyStatusTable()
		{
			try
			{

			//	ClientConnectionString = @"Data Source=" + AppDomain.CurrentDomain.BaseDirectory + "SuperNodeBuddyInfo.sdf";
			//	strLocalDBPath = AppDomain.CurrentDomain.BaseDirectory + "SuperNodeBuddyInfo.sdf";


				if (false == File.Exists(strLocalDBPath))
				{
					SqlCeEngine clientEngine = new SqlCeEngine(ClientConnectionString);
					clientEngine.CreateDatabase();
				}
				if (!IsTableExits("Node_Status"))
				{
					SqlCeClientSyncProvider sync = new SqlCeClientSyncProvider(ClientConnectionString);

					SyncTable tblNode_Status = new SyncTable("Node_Status");

					SyncSchema syncSchemaLead = new SyncSchema();
					syncSchemaLead.Tables.Add("Node_Status");
					syncSchemaLead.Tables["Node_Status"].Columns.Add("Buddy_ID");
					syncSchemaLead.Tables["Node_Status"].Columns["Buddy_ID"].ProviderDataType = SqlDbType.BigInt.ToString();
					syncSchemaLead.Tables["Node_Status"].Columns["Buddy_ID"].AutoIncrement = true;
					syncSchemaLead.Tables["Node_Status"].Columns["Buddy_ID"].AutoIncrementSeed = 1;
					syncSchemaLead.Tables["Node_Status"].Columns["Buddy_ID"].AutoIncrementStep = 1;
					syncSchemaLead.Tables["Node_Status"].PrimaryKey = new string[] { "Buddy_ID" };

					syncSchemaLead.Tables["Node_Status"].Columns.Add("Buddy_Name");
					syncSchemaLead.Tables["Node_Status"].Columns["Buddy_Name"].ProviderDataType = SqlDbType.NVarChar.ToString();
					syncSchemaLead.Tables["Node_Status"].Columns["Buddy_Name"].MaxLength = 30;

					syncSchemaLead.Tables["Node_Status"].Columns.Add("Buddy_Status");
					syncSchemaLead.Tables["Node_Status"].Columns["Buddy_Status"].ProviderDataType = SqlDbType.NVarChar.ToString();
					syncSchemaLead.Tables["Node_Status"].Columns["Buddy_Status"].MaxLength = 30;

					sync.CreateSchema(tblNode_Status, syncSchemaLead);
				}
				if (VMuktiInfo.CurrentPeer.DisplayName != null && VMuktiInfo.CurrentPeer.DisplayName != string.Empty)
				{
					fncSNInsertBuddy(VMuktiInfo.CurrentPeer.DisplayName, "Online");
				}
			}
			catch (Exception ex)
			{
				// MessageBox.Show("Error In Creating Node_Status Table");
				ex.Data.Add("My Key", "fncCreateBuddyStatusTable()--:--SuperNodeDomain.cs--:--" + ex.Message + " :--:--");
				ClsException.LogError(ex);
				ClsException.WriteToErrorLogFile(ex);
			}
		}

		public void fncCreateSNNodeInfoTable()
		{
			try
			{
			//	ClientConnectionString = @"Data Source=" + AppDomain.CurrentDomain.BaseDirectory + "SuperNodeBuddyInfo.sdf";
			//	strLocalDBPath = AppDomain.CurrentDomain.BaseDirectory + "SuperNodeBuddyInfo.sdf";

				if (false == File.Exists(strLocalDBPath))
				{
					SqlCeEngine clientEngine = new SqlCeEngine(ClientConnectionString);
					clientEngine.CreateDatabase();
				}
				if (!IsTableExits("Node_Info"))
				{
					SqlCeClientSyncProvider sync = new SqlCeClientSyncProvider(ClientConnectionString);

					SyncTable tblNode_Info = new SyncTable("Node_Info");

					SyncSchema syncSchemaLead = new SyncSchema();
					syncSchemaLead.Tables.Add("Node_Info");
					syncSchemaLead.Tables["Node_Info"].Columns.Add("Node_ID");
					syncSchemaLead.Tables["Node_Info"].Columns["Node_ID"].ProviderDataType = SqlDbType.BigInt.ToString();
					syncSchemaLead.Tables["Node_Info"].Columns["Node_ID"].AutoIncrement = true;
					syncSchemaLead.Tables["Node_Info"].Columns["Node_ID"].AutoIncrementSeed = 1;
					syncSchemaLead.Tables["Node_Info"].Columns["Node_ID"].AutoIncrementStep = 1;
					syncSchemaLead.Tables["Node_Info"].PrimaryKey = new string[] { "Node_ID" };

					syncSchemaLead.Tables["Node_Info"].Columns.Add("Node_Name");
					syncSchemaLead.Tables["Node_Info"].Columns["Node_Name"].ProviderDataType = SqlDbType.NVarChar.ToString();
					syncSchemaLead.Tables["Node_Info"].Columns["Node_Name"].MaxLength = 30;

					sync.CreateSchema(tblNode_Info, syncSchemaLead);
				}
			}
			catch (Exception ex)
			{
				//MessageBox.Show("Error In Creating Node_Info Table");
				ex.Data.Add("My Key", "fncCreateSNNodeInfoTable()--:--SuperNodeDomain.cs--:--" + ex.Message + " :--:--");
				ClsException.LogError(ex);
				ClsException.WriteToErrorLogFile(ex);
			}
		}

		public void fncCreateUserBuddyListTable()
		{
			try
			{
			//	ClientConnectionString = @"Data Source=" + AppDomain.CurrentDomain.BaseDirectory + "SuperNodeBuddyInfo.sdf";
			//	strLocalDBPath = AppDomain.CurrentDomain.BaseDirectory + "SuperNodeBuddyInfo.sdf";

				if (false == File.Exists(strLocalDBPath))
				{
					SqlCeEngine clientEngine = new SqlCeEngine(ClientConnectionString);
					clientEngine.CreateDatabase();
				}
				if (!IsTableExits("User_BuddyList"))
				{
					SqlCeClientSyncProvider sync = new SqlCeClientSyncProvider(ClientConnectionString);

					SyncTable tblUser_BuddyList = new SyncTable("User_BuddyList");

					SyncSchema syncSchemaLead = new SyncSchema();
					syncSchemaLead.Tables.Add("User_BuddyList");
					syncSchemaLead.Tables["User_BuddyList"].Columns.Add("ID");
					syncSchemaLead.Tables["User_BuddyList"].Columns["ID"].ProviderDataType = SqlDbType.BigInt.ToString();
					syncSchemaLead.Tables["User_BuddyList"].Columns["ID"].AutoIncrement = true;
					syncSchemaLead.Tables["User_BuddyList"].Columns["ID"].AutoIncrementSeed = 1;
					syncSchemaLead.Tables["User_BuddyList"].Columns["ID"].AutoIncrementStep = 1;
					syncSchemaLead.Tables["User_BuddyList"].PrimaryKey = new string[] { "ID" };

					syncSchemaLead.Tables["User_BuddyList"].Columns.Add("UserName");
					syncSchemaLead.Tables["User_BuddyList"].Columns["UserName"].ProviderDataType = SqlDbType.NVarChar.ToString();
					syncSchemaLead.Tables["User_BuddyList"].Columns["UserName"].MaxLength = 30;
					syncSchemaLead.Tables["User_BuddyList"].Columns["UserName"].AllowNull = false;


					syncSchemaLead.Tables["User_BuddyList"].Columns.Add("BuddyName");
					syncSchemaLead.Tables["User_BuddyList"].Columns["BuddyName"].ProviderDataType = SqlDbType.NVarChar.ToString();
					syncSchemaLead.Tables["User_BuddyList"].Columns["BuddyName"].MaxLength = 30;
					syncSchemaLead.Tables["User_BuddyList"].Columns["BuddyName"].AllowNull = false;

					syncSchemaLead.Tables["User_BuddyList"].Columns.Add("BuddyStatus");
					syncSchemaLead.Tables["User_BuddyList"].Columns["BuddyStatus"].ProviderDataType = SqlDbType.NVarChar.ToString();
					syncSchemaLead.Tables["User_BuddyList"].Columns["BuddyStatus"].MaxLength = 20;
					syncSchemaLead.Tables["User_BuddyList"].Columns["BuddyStatus"].AllowNull = false;


					sync.CreateSchema(tblUser_BuddyList, syncSchemaLead);
				}
			}
			catch (Exception ex)
			{
				//MessageBox.Show("Error In Creating Node_Info Table");
				ex.Data.Add("My Key", "fncCreateSNNodeInfoTable()--:--SuperNodeDomain.cs--:--" + ex.Message + " :--:--");
				ClsException.LogError(ex);
				ClsException.WriteToErrorLogFile(ex);
			}
		}

		public bool IsTableExits(string strTableName)
		{
		//	SqlCeConnection ce = new SqlCeConnection(ClientConnectionString);
			try
			{
			//	ce.Open();
                OpenConnection();
				string str = "SELECT COUNT(*) FROM Information_Schema.Tables WHERE (TABLE_NAME ='" + strTableName + "')";
                SqlCeCommand cmd = new SqlCeCommand(str, LocalSQLConn);
				object i = cmd.ExecuteScalar();
			//	ce.Close();
			//	ce.Dispose();
				if (int.Parse(i.ToString()) > 0)
				{
					return true;
				}
				else
				{
					return false;
				}


			}
			catch (Exception ex)
			{
				// MessageBox.Show("Exception In Table Checking Table Status");
				ex.Data.Add("My Key", "IsTableExits()--:--SuperNodeDomain.cs--:--" + ex.Message + " :--:--");
				ClsException.LogError(ex);
				ClsException.WriteToErrorLogFile(ex);
			//	ce.Close();
			//	ce.Dispose();
				return false;
			}
		}

		private bool IsRecordExists(string strBuddyName, string strTableName, string strPrimaryKey)
		{
		//	SqlCeConnection ce = new SqlCeConnection(ClientConnectionString);
			try
			{
			//	ce.Open();
                OpenConnection();
				string str = "SELECT COUNT(*) FROM " + strTableName + " WHERE (" + strPrimaryKey + " ='" + strBuddyName + "')";
				//string str = "Select Count(*) From Loginserver_Master";
                SqlCeCommand cmd = new SqlCeCommand(str, LocalSQLConn);

				object i = cmd.ExecuteScalar();
			//	ce.Close();
			//	ce.Dispose();
				if (int.Parse(i.ToString()) > 0)
				{
					return true;
				}
				else
				{
					return false;
				}
			}
			catch (Exception ex)
			{
				//MessageBox.Show("Exception In Checking Record Exist");
				ex.Data.Add("My Key", "IsRecordExists()--:--SuperNodeDomain.cs--:--" + ex.Message + " :--:--");
				ClsException.LogError(ex);
				ClsException.WriteToErrorLogFile(ex);
			//	ce.Close();
			//	ce.Dispose();
				return false;
			}

		}

		public void fncSNInsertBuddy(string strBuddyName, string strBuddyStatus)
		{
		//	SqlCeConnection ceConn = new SqlCeConnection(ClientConnectionString);
			try
			{

				if (!IsRecordExists(strBuddyName, "Node_Status", "Buddy_Name"))
				{
				//	ceConn.Open();
                    OpenConnection();
					string str = "insert into Node_Status(Buddy_Name,Buddy_Status) values(@Buddy_Name,@Buddy_Status) ";
					SqlCeCommand cmd = new SqlCeCommand(str);
                    cmd.Connection = LocalSQLConn;

					cmd.Parameters.AddWithValue("@Buddy_Name", strBuddyName);
					cmd.Parameters.AddWithValue("@Buddy_Status", strBuddyStatus);
					cmd.ExecuteNonQuery();
				//	ceConn.Close();
				//	ceConn.Dispose();
				}
				else
				{
				//	ceConn.Open();
                    OpenConnection();
					string str = "Update Node_Status Set Buddy_Status='" + strBuddyStatus + "' Where Buddy_Name='" + strBuddyName + "'";
					SqlCeCommand cmd = new SqlCeCommand(str);
                    cmd.Connection = LocalSQLConn;
					cmd.ExecuteNonQuery();
				//	ceConn.Close();
				//	ceConn.Dispose();
				}
				// MessageBox.Show("Buddy " + strBuddyName + " is " + strBuddyStatus,"SuperNode Domain");
			}
			catch (Exception ex)
			{
				// MessageBox.Show("Error In Inserting Value from NodeStatus table on SuperNdoeMachine");
				ex.Data.Add("My Key", "fncSNInsertBuddy()--:--SuperNodeDomain.cs--:--" + ex.Message + " :--:--");
				ClsException.LogError(ex);
				ClsException.WriteToErrorLogFile(ex);
			//	ceConn.Close();
			//	ceConn.Dispose();
			}
		}

		private void fncSNDeleteBuddy(string strBuddyName)
		{
			//SqlCeConnection ceConn = new SqlCeConnection(ClientConnectionString);
			try
			{

				if (IsRecordExists(strBuddyName, "Node_Status", "Buddy_Name"))
				{
				//	ceConn.Open();
                    OpenConnection();
					string str = "delete from Node_Status where Buddy_Name = @Buddy_Name";
					SqlCeCommand cmd = new SqlCeCommand(str);
                    cmd.Connection = LocalSQLConn;

					cmd.Parameters.AddWithValue("@Buddy_Name", strBuddyName);
					cmd.ExecuteNonQuery();
				//	ceConn.Close();
				//	ceConn.Dispose();
				}
			}
			catch (Exception ex)
			{
				// MessageBox.Show("Error In Deleteing Value from NodeStatus table on SuperNdoeMachine.");
				ex.Data.Add("My Key", "fncSNDeleteBuddy()--:--SuperNodeDomain.cs--:--" + ex.Message + " :--:--");
				ClsException.LogError(ex);
				ClsException.WriteToErrorLogFile(ex);
                //if (ceConn.State == ConnectionState.Open)
                //{
                //    ceConn.Close();
                //    ceConn.Dispose();
                //}
			}
		}

		private void fncSNInsertNode(string uName)
		{
		//	SqlCeConnection ceConn = new SqlCeConnection(ClientConnectionString);
			try
			{
				if (!IsRecordExists(uName, "Node_Info", "Node_Name"))
				{

			//		ceConn.Open();
                    OpenConnection();
					string str = "insert into Node_Info(Node_Name) values(@Node_Name) ";
					SqlCeCommand cmd = new SqlCeCommand(str);
                    cmd.Connection = LocalSQLConn;

					cmd.Parameters.AddWithValue("@Node_Name", uName);
					cmd.ExecuteNonQuery();
			//		ceConn.Close();
			//		ceConn.Dispose();
				}
			}
			catch (Exception ex)
			{
				//MessageBox.Show("Error In Inserting Value from NodeInfo table on SuperNdoeMachine");
				ex.Data.Add("My Key", "fncSNInsertNode()--:--SuperNodeDomain.cs--:--" + ex.Message + " :--:--");
				ClsException.LogError(ex);
				ClsException.WriteToErrorLogFile(ex);
                //if (ceConn.State == ConnectionState.Open)
                //{
                //    ceConn.Close();
                //    ceConn.Dispose();
                //}
			}
		}

		private void fncSNDeleteNode(string uName)
		{
		//	SqlCeConnection ceConn = new SqlCeConnection(ClientConnectionString);
			try
			{
				if (IsRecordExists(uName, "Node_Info", "Node_Name"))
				{
				//	ceConn.Open();
                    OpenConnection();
					string str = "delete from Node_Info where Node_Name = @Node_Name";
					SqlCeCommand cmd = new SqlCeCommand(str);
                    cmd.Connection = LocalSQLConn;

					cmd.Parameters.AddWithValue("@Node_Name", uName);
					cmd.ExecuteNonQuery();
				//	ceConn.Close();
				//	ceConn.Dispose();
				}
			}
			catch (Exception ex)
			{
				// MessageBox.Show("Error In Deleteing Value from NodeInfo table on SuperNdoeMachine.");
				ex.Data.Add("My Key", "fncSNDeleteNode()--:--SuperNodeDomain.cs--:--" + ex.Message + " :--:--");
				ClsException.LogError(ex);
				ClsException.WriteToErrorLogFile(ex);
                //if (ceConn.State == ConnectionState.Open)
                //{
                //    ceConn.Close();
                //}
                //ceConn.Dispose();
			}
		}

		private List<string> fncGetOnlineBuddies()
		{
			//SqlCeConnection SNConn = null;
			try
			{
			//	ClientConnectionString = @"Data Source=" + AppDomain.CurrentDomain.BaseDirectory + "SuperNodeBuddyInfo.sdf";
			//	strLocalDBPath = AppDomain.CurrentDomain.BaseDirectory + "SuperNodeBuddyInfo.sdf";

				if (false == File.Exists(strLocalDBPath))
				{
					SqlCeEngine clientEngine = new SqlCeEngine(ClientConnectionString);
					clientEngine.CreateDatabase();
				}
			//	SNConn = new SqlCeConnection(ClientConnectionString);
			//	SNConn.Open();
                OpenConnection();
				SqlCeDataAdapter sqlDataAdap = null;
                sqlDataAdap = new SqlCeDataAdapter("SELECT * FROM Node_Status", LocalSQLConn);
				DataTable myDT = new DataTable();
				sqlDataAdap.Fill(myDT);
				List<string> lstOnlineBuddyList = new List<string>();
				for (int i = 0; i < myDT.Rows.Count; i++)
				{
					lstOnlineBuddyList.Add(myDT.Rows[i][1].ToString());
				}
				sqlDataAdap.Dispose();
			//	SNConn.Close();
			//	SNConn.Dispose();
				return lstOnlineBuddyList;
			}
			catch (Exception ex)
			{
				// MessageBox.Show("Error in retriving OnlineBuddyList by NetP2P :::" + ex.Message);
				ex.Data.Add("My Key", "fncGetOnlineBuddies()--:--SuperNodeDomain.cs--:--" + ex.Message + " :--:--");
				ClsException.LogError(ex);
				ClsException.WriteToErrorLogFile(ex);
                //if (SNConn != null)
                //{
                //    SNConn.Close();
                //    SNConn.Dispose();
                //}
				return null;
			}
		}

		private void fncUpdateUserBuddyStatus(string BuddName, string status)
		{
			//SqlCeConnection ceConn = new SqlCeConnection(ClientConnectionString);
			try
			{
				//ceConn.Open();
				//string strCommand = "Select Count(*) From User_BuddyList Where UserName = '" + userName + "' and BuddyName = '" + BuddName + "'";

				//SqlCeCommand cmd = new SqlCeCommand("SELECT COUNT(*) FROM User_BuddyList WHERE (UserName = '" + VMuktiAPI.VMuktiInfo.CurrentPeer.DisplayName + "') AND (BuddyName = '" + BuddName + "')", ceConn);
				//object i = cmd.ExecuteScalar();
				//if (int.Parse(i.ToString()) > 0)
				//{
				//    cmd = new SqlCeCommand("Update User_BuddyList Set BuddyStatus='" + status + "' Where (UserName = '" + VMuktiAPI.VMuktiInfo.CurrentPeer.DisplayName + "') AND (BuddyName = '" + BuddName + "')", ceConn);
				//    cmd.ExecuteNonQuery();
				//}
                OpenConnection();
                SqlCeCommand cmd = new SqlCeCommand("Update User_BuddyList Set BuddyStatus='" + status + "' Where BuddyName = '" + BuddName + "'", LocalSQLConn);
				cmd.ExecuteNonQuery();
			//	ceConn.Close();
			//	ceConn.Dispose();
			}
			catch (Exception ex)
			{
				ex.Data.Add("My Key", "fncUpdateUserBuddyStatus()--:--SuperNodeDomain.cs--:--" + ex.Message + " :--:--");
				ClsException.LogError(ex);
				ClsException.WriteToErrorLogFile(ex);
                //ceConn.Close();
                //ceConn.Dispose();
			}
		}

		private void fncUpdateBuddyStatus(string userName, string BuddName, string status)
		{
		//	SqlCeConnection ceConn = new SqlCeConnection(ClientConnectionString);
			try
			{
			//	ceConn.Open();
				//string strCommand = "Select Count(*) From User_BuddyList Where UserName = '" + userName + "' and BuddyName = '" + BuddName + "'";
                OpenConnection();
                SqlCeCommand cmd = new SqlCeCommand("SELECT COUNT(*) FROM User_BuddyList WHERE (UserName = '" + userName + "') AND (BuddyName = '" + BuddName + "')", LocalSQLConn);
				object i = cmd.ExecuteScalar();
				if (int.Parse(i.ToString()) > 0)
				{
                    cmd = new SqlCeCommand("Update User_BuddyList Set BuddyStatus ='" + status + "' Where (UserName = '" + userName + "') AND (BuddyName = '" + BuddName + "')", LocalSQLConn);
					cmd.ExecuteNonQuery();
				}
				else
				{
					string str = "insert into User_BuddyList(UserName,BuddyName,BuddyStatus) values(@UserName,@BuddyName,@BuddyStatus) ";
					cmd = new SqlCeCommand(str);
                    cmd.Connection = LocalSQLConn;

					cmd.Parameters.AddWithValue("@UserName", userName);
					cmd.Parameters.AddWithValue("@BuddyName", BuddName);
					cmd.Parameters.AddWithValue("@BuddyStatus", status);
					cmd.ExecuteNonQuery();

				}
                //ceConn.Close();
                //ceConn.Dispose();
			}

			catch (Exception ex)
			{
				ex.Data.Add("My Key", "fncUpdateBuddyStatus()--:--SuperNodeDomain.cs--:--" + ex.Message + " :--:--");
				ClsException.LogError(ex);
				ClsException.WriteToErrorLogFile(ex);
			//	ceConn.Close();
			//	ceConn.Dispose();
			}

		}

        void OpenConnection()
        {
            try
            {
                if (LocalSQLConn.State != ConnectionState.Open)
                {
                    LocalSQLConn.Open();
                }
            }
            catch (Exception ex)
            {
                ex.Data.Add("My Key", "OpenConnection()--:--BootStrapDomain.cs--:--" + ex.Message + " :--:--");
                ClsException.LogError(ex);
                ClsException.WriteToErrorLogFile(ex);
            }

        }



		#endregion

		public void ShowDirectory(DirectoryInfo dir)
		{
			foreach (FileInfo file in dir.GetFiles())
			{
				int hj = al.Add(file.FullName);
			}
			foreach (DirectoryInfo subDir in dir.GetDirectories())
			{
				ShowDirectory(subDir);
			}
		}

		public void DownloadZipFiles()
		{
			try
			{
				//ClsModuleCollection cmc = ClsModuleCollection.GetOnlyCollMod();
                ClsModuleCollection cmc = ClsModuleCollection.GetAll();
				ass = Assembly.GetAssembly(typeof(SuperNodeServiceDomain));
				for (int i = 0; i < cmc.Count; i++)
				{
					try
					{
						#region Downloading ZipFile

						string filename = cmc[i].ZipFile;
						//Uri u = new Uri("http://" + VMuktiAPI.VMuktiInfo.BootStrapIPs[0] + "/VMukti/" + filename);
                        Uri u = new Uri(VMuktiAPI.VMuktiInfo.ZipFileDownloadLink + filename);
						if (!Directory.Exists(ass.Location.Replace("VMukti.Presentation.exe", @"Zip Files")))
						{
							Directory.CreateDirectory(ass.Location.Replace("VMukti.Presentation.exe", @"Zip Files"));
						}
						string destination = ass.Location.Replace("VMukti.Presentation.exe", @"Zip Files");
						if (!File.Exists(destination + "\\" + filename))
						{
							WebClient wc = new WebClient();
							wc.DownloadFile(u, destination + "\\" + filename);
						}

						#endregion

						#region Extracting

						string strModPath = ass.Location.Replace("VMukti.Presentation.exe", @"Modules");
						VMukti.ZipUnzip.Zip.FastZip fz = new VMukti.ZipUnzip.Zip.FastZip();
						if (!Directory.Exists(strModPath + "\\" + filename.Split('.')[0]))
						{
							fz.ExtractZip(destination + "\\" + filename, strModPath, null);
						}

						#endregion
						string strXmlPath = strModPath + "\\" + filename.Split('.')[0] + "\\Control\\configuration.xml";
						if (File.Exists(strXmlPath))
						{
							#region Parsing XML

							XmlParser xp = new XmlParser();
							xp.Parse(strXmlPath);

							#endregion

							#region Loading ReferencedAssemblies
							al.Clear();
							DirectoryInfo dirinfomodule = new DirectoryInfo(strModPath + "\\" + filename.Split('.')[0]);
							ShowDirectory(dirinfomodule);

							for (int j = 0; j < al.Count; j++)
							{
								string[] arraysplit = al[j].ToString().Split('\\');
								if (arraysplit[arraysplit.Length - 1].ToString() == cmc[i].AssemblyFile)
								{
									assDownload = Assembly.LoadFrom(al[j].ToString());
									AssemblyName[] an = assDownload.GetReferencedAssemblies();

									for (int alcount = 0; alcount < al.Count; alcount++)
									{
										string strsplit = al[alcount].ToString();
										string[] strold = strsplit.Split('\\');
										string strnew = strold[strold.Length - 1].Substring(0, strold[strold.Length - 1].Length - 4);

										for (int asscount = 0; asscount < an.Length; asscount++)
										{
											if (an[asscount].Name == strnew)
											{
												Assembly assbal = System.AppDomain.CurrentDomain.Load(System.Reflection.Assembly.LoadFrom(al[alcount].ToString()).GetName());
												AssemblyName[] anbal = assbal.GetReferencedAssemblies();
												for (int andal = 0; andal < al.Count; andal++)
												{
													string strsplitdal = al[andal].ToString();
													string[] strolddal = strsplitdal.Split('\\');
													string strnewdal = strolddal[strolddal.Length - 1].Substring(0, strolddal[strolddal.Length - 1].Length - 4);

													for (int asscountdal = 0; asscountdal < anbal.Length; asscountdal++)
													{
														if (anbal[asscountdal].Name == strnewdal)
														{
															Assembly assdal = System.AppDomain.CurrentDomain.Load(System.Reflection.Assembly.LoadFrom(al[andal].ToString()).GetName());
														}
													}
												}
											}
										}
									}
									Type[] t1 = assDownload.GetTypes();
									#region CreatingObject

									for (int k = 0; k < t1.Length; k++)
									{
										if (t1[k].Name == xp.xMain.SuperNodeClass)
										{
											try
											{
												object obj1 = Activator.CreateInstance(t1[k]);
												lstObjSuperNode.Add(obj1);
												break;
											}

											catch (Exception exp)
											{
												//MessageBox.Show("CreatingObject " + exp.Message);
												//if (exp.InnerException != null)
												//{
												//    MessageBox.Show(exp.InnerException.Message);
												//}
												exp.Data.Add("My Key", "CreatingObject-5--:--CtlPageTab.cs--:--" + exp.Message + " :--:--");
												ClsException.LogError(exp);
												ClsException.WriteToErrorLogFile(exp);

											}
										}
									}
									#endregion
								}
							}
							#endregion
						}
					}
					catch (Exception exp)
					{
						//System.Windows.MessageBox.Show("btnSubmit_Click - 1" + exp.Message);
                        exp.Data.Add("My Key", "btnSubmit_Click - 1--:--SuperNodeServiceDomain.cs--:--" + exp.Message + " :--:--");
                        ClsException.LogError(exp);
                        ClsException.WriteToErrorLogFile(exp);
					}
				}
			}
			catch (Exception exp)
			{
				//System.Windows.MessageBox.Show("btnSubmit_Click - 2" + exp.Message);
				exp.Data.Add("My Key", "btnSubmit_Click - 2--:--SuperNodeServiceDomain.cs--:--" + exp.Message + " :--:--");
				ClsException.LogError(exp);
				ClsException.WriteToErrorLogFile(exp);
			}
		}

		public void CopyToBase(string modulename, string filename)
		{
            try
            {
                if (!File.Exists(AppDomain.CurrentDomain.BaseDirectory + filename))
                {
                    string[] ControlFiles = Directory.GetFiles(AppDomain.CurrentDomain.BaseDirectory + "\\Modules\\" + modulename + "\\Control", "*.dll");
                    string[] BalFiles = Directory.GetFiles(AppDomain.CurrentDomain.BaseDirectory + "\\Modules\\" + modulename + "\\Bal", "*.dll");
                    for (int i = 0; i < ControlFiles.Length; i++)
                    {
                        FileInfo fi = new FileInfo(ControlFiles[i]);
                        //MessageBox.Show(fi.Name);
                        fi.CopyTo(AppDomain.CurrentDomain.BaseDirectory + "\\" + fi.Name);
                    }
                    foreach (string str in BalFiles)
                    {
                        FileInfo fi = new FileInfo(str);
                        //MessageBox.Show(fi.Name);
                        if (!File.Exists(AppDomain.CurrentDomain.BaseDirectory + "\\" + fi.Name))
                        {
                            fi.CopyTo(AppDomain.CurrentDomain.BaseDirectory + "\\" + fi.Name);
                        }
                    }
                }
            }
            catch (Exception exp)
            {
                exp.Data.Add("My Key", "CopyToBase()--:--SuperNodeServiceDomain.cs--:--" + exp.Message + " :--:--");
                ClsException.LogError(exp);
                ClsException.WriteToErrorLogFile(exp);
            }
		}

		~SuperNodeServiceDomain()
		{
			Dispose();
		}

		#region IDisposable Members

		public void Dispose()
		{
			if (objHttpSuperNode != null)
			{
				objHttpSuperNode = null;
			}

			if (npsSuperNodeServer != null)
			{
				npsSuperNodeServer = null;
			}
			if (npsModules != null)
			{
				npsModules = null;
			}

			if (lstmyNodes != null)
			{
				lstmyNodes = null;
			}
			if (objFileStream != null)
			{
				objFileStream = null;
			}

			if (strBuddyName != null)
			{
				strBuddyName = null;
			}

			//if (objNetP2PBootStrapPredictive != null)
			//{                
			//    objNetP2PBootStrapPredictive = null;
			//}
			//if (ClientNetP2PPredictiveChannel != null)
			//{                
			//    ClientNetP2PPredictiveChannel = null;
			//}

			if (objNetP2PBootStrap != null)
			{
				objNetP2PBootStrap = null;
			}
			if (clientNetP2pChannelBS != null)
			{
				clientNetP2pChannelBS = null;
			}

			//if (objNetP2PBootStrapPBX != null)
			//{
			//    objNetP2PBootStrapPBX = null;
			//}
			//if (ClientNetP2PPBXServerChannel != null)
			//{
			//    ClientNetP2PPBXServerChannel = null;
			//}

			if (clientHttpChannelBS != null)
			{
				clientHttpChannelBS = null;
			}
			if (objSIPInformation != null)
			{
				objSIPInformation = null;
			}
			if (objNetP2PSuperNode != null)
			{
				objNetP2PSuperNode = null;
			}
			if (clientNetP2PChannelSN != null)
			{
				clientNetP2PChannelSN = null;
			}
			if (lstObjRTCAuthClient != null)
			{
				lstObjRTCAuthClient = null;
			}
			if (lstObjSuperNode != null)
			{
				lstObjSuperNode = null;
			}
		}

		#endregion
	}
}
